aashu-0 commited on
Commit
b16b7f0
Β·
verified Β·
1 Parent(s): 7abd4f4
Files changed (1) hide show
  1. app.py +15 -54
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. <br>Dataset: [Food-101](https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/)"
48
- article = "Created by [Your Name](https://github.com/aashu-0/Food101) ❀️"
49
 
50
  # Example images
51
  example_list = [['examples/' + example] for example in os.listdir('examples')]
52
 
53
- with gr.Blocks() as demo:
54
- gr.Markdown(f"# {title}")
55
- gr.Markdown(description)
56
-
57
- # Input mode radio
58
- input_mode = gr.Radio(
59
- choices=["Upload", "Camera"],
60
- value="Upload",
61
- label="Image Input Method"
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
- if __name__ == "__main__":
105
- demo.launch(share=True)
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