samithcs commited on
Commit
35783a0
·
verified ·
1 Parent(s): 25c5985

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from src.pipeline.prediction_pipeline import PredictionPipeline
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ pipeline = PredictionPipeline()
7
+
8
+ def predict_single(image):
9
+
10
+ if image is None:
11
+ return None, "No image detected!", "No image detected!"
12
+ img = Image.fromarray(image) if isinstance(image, np.ndarray) else image
13
+ result = pipeline.predict(img)
14
+ annotated_img = pipeline.annotate(img, result)
15
+ return annotated_img, result["category"], result["freshness"]
16
+
17
+ with gr.Blocks() as demo:
18
+ gr.Markdown("# Food Freshness Detection")
19
+
20
+ with gr.Tab("Image Upload"):
21
+ image = gr.Image(sources=["upload"], label="Upload an Image")
22
+ out_img = gr.Image()
23
+ cat = gr.Textbox(label="Category")
24
+ fresh = gr.Textbox(label="Freshness")
25
+ btn = gr.Button("Predict on Image")
26
+ btn.click(predict_single, inputs=image, outputs=[out_img, cat, fresh])
27
+
28
+
29
+ with gr.Tab("Live Webcam"):
30
+ webcam = gr.Image(sources=["webcam"], label="Webcam")
31
+ out_img = gr.Image()
32
+ cat = gr.Textbox(label="Category")
33
+ fresh = gr.Textbox(label="Freshness")
34
+ btn = gr.Button("Predict")
35
+ btn.click(predict_single, inputs=webcam, outputs=[out_img, cat, fresh])
36
+
37
+
38
+
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch(server_name="0.0.0.0", server_port=7860)