miwojc commited on
Commit
9c6eed2
·
1 Parent(s): 3fb7df9

Create new file

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ from huggingface_hub import from_pretrained_fastai
4
+
5
+ repo_id = "hugginglearners/kvasir-seg"
6
+ learn = from_pretrained_fastai(repo_id)
7
+ #labels = learn.dls.vocab
8
+
9
+ def predict(img):
10
+ img = PILImage.create(img)
11
+ pred, _, _ = learn.predict(img)
12
+ return PILMask.create(pred*255)
13
+
14
+ interface_options = {
15
+ "title": "kvasir-seg fastai segmentation",
16
+ "description": "tbd",
17
+ "interpretation": "default",
18
+ "layout": "horizontal",
19
+ # "examples": [
20
+ # "100098.jpg",
21
+ # "100002.jpg",
22
+ # "100048.jpg"
23
+ ],
24
+ "allow_flagging": "never",
25
+ }
26
+
27
+ demo = gr.Interface(
28
+ fn=predict,
29
+ inputs=gr.inputs.Image(shape=(224, 224)),
30
+ outputs=gr.inputs.Image(shape=(224, 224)),
31
+ **interface_options,
32
+ )
33
+
34
+ launch_options = {
35
+ "enable_queue": True,
36
+ "share": False,
37
+ }
38
+
39
+ demo.launch(**launch_options)