Spaces:
Sleeping
Sleeping
:)
Browse files
app.py
CHANGED
@@ -44,63 +44,24 @@ def predict(img) -> Tuple[Dict, float]:
|
|
44 |
|
45 |
# Gradio app
|
46 |
title = "Food101 ππͺ"
|
47 |
-
description = "EfficientNetB2 model to classify food images into 101 classes.
|
48 |
-
article = "Created
|
49 |
|
50 |
# Example images
|
51 |
example_list = [['examples/' + example] for example in os.listdir('examples')]
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
# Dynamic image input
|
65 |
-
image_input = gr.Image(
|
66 |
-
type="pil",
|
67 |
-
label="Food Image",
|
68 |
-
source="upload",
|
69 |
-
interactive=True
|
70 |
-
)
|
71 |
-
|
72 |
-
# Update image source based on input mode
|
73 |
-
input_mode.change(
|
74 |
-
fn=lambda mode: gr.update(source="upload" if mode == "Upload" else "webcam"),
|
75 |
-
inputs=input_mode,
|
76 |
-
outputs=image_input
|
77 |
-
)
|
78 |
-
|
79 |
-
# Predict button
|
80 |
-
predict_btn = gr.Button("Classify π")
|
81 |
-
|
82 |
-
# Outputs
|
83 |
-
label_output = gr.Label(num_top_classes=5, label="Predictions")
|
84 |
-
time_output = gr.Number(label="Prediction Time (s)")
|
85 |
-
|
86 |
-
# Examples
|
87 |
-
gr.Examples(
|
88 |
-
examples=example_list,
|
89 |
-
inputs=image_input,
|
90 |
-
outputs=[label_output, time_output],
|
91 |
-
fn=predict,
|
92 |
-
cache_examples=True
|
93 |
-
)
|
94 |
-
|
95 |
-
# Prediction handler
|
96 |
-
predict_btn.click(
|
97 |
-
fn=predict,
|
98 |
-
inputs=image_input,
|
99 |
-
outputs=[label_output, time_output]
|
100 |
-
)
|
101 |
-
|
102 |
-
gr.Markdown(article)
|
103 |
|
104 |
-
|
105 |
-
|
106 |
|
|
|
44 |
|
45 |
# Gradio app
|
46 |
title = "Food101 ππͺ"
|
47 |
+
description = "EfficientNetB2 model to classify food images into 101 classes. Dataset: [Food-101](https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/)"
|
48 |
+
article = "Created with β€οΈ [github/aashu-0](https://github.com/aashu-0/Food101)"
|
49 |
|
50 |
# Example images
|
51 |
example_list = [['examples/' + example] for example in os.listdir('examples')]
|
52 |
|
53 |
+
# gradio demo
|
54 |
+
demo = gr.Interface(fn= predict,
|
55 |
+
inputs = gr.Image(type= 'pil'),
|
56 |
+
outputs= [gr.Label(num_top_classes=5, label='Predictions'),
|
57 |
+
gr.Number(label="Predictions time(in seconds)")],
|
58 |
+
examples=example_list,
|
59 |
+
title=title,
|
60 |
+
description=description,
|
61 |
+
article=article,
|
62 |
+
live= True
|
63 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
# launch
|
66 |
+
demo.launch(share=True)
|
67 |
|