samithcs commited on
Commit
9de7b12
·
2 Parent(s): 10119d7 5aa45b9

Merge branch 'main' of https://huggingface.co/spaces/samithcs/Image-Based-Food-Freshness-Prediction-System

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  from src.pipeline.prediction_pipeline import PredictionPipeline
3
  import numpy as np
@@ -39,3 +40,46 @@ with gr.Blocks() as demo:
39
 
40
  if __name__ == "__main__":
41
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <<<<<<< HEAD
2
  import gradio as gr
3
  from src.pipeline.prediction_pipeline import PredictionPipeline
4
  import numpy as np
 
40
 
41
  if __name__ == "__main__":
42
  demo.launch(server_name="0.0.0.0", server_port=7860)
43
+ =======
44
+ import gradio as gr
45
+ from src.pipeline.prediction_pipeline import PredictionPipeline
46
+ import numpy as np
47
+ from PIL import Image
48
+
49
+ pipeline = PredictionPipeline()
50
+
51
+ def predict_single(image):
52
+
53
+ if image is None:
54
+ return None, "No image detected!", "No image detected!"
55
+ img = Image.fromarray(image) if isinstance(image, np.ndarray) else image
56
+ result = pipeline.predict(img)
57
+ annotated_img = pipeline.annotate(img, result)
58
+ return annotated_img, result["category"], result["freshness"]
59
+
60
+ with gr.Blocks() as demo:
61
+ gr.Markdown("# Food Freshness Detection")
62
+
63
+ with gr.Tab("Image Upload"):
64
+ image = gr.Image(sources=["upload"], label="Upload an Image")
65
+ out_img = gr.Image()
66
+ cat = gr.Textbox(label="Category")
67
+ fresh = gr.Textbox(label="Freshness")
68
+ btn = gr.Button("Predict on Image")
69
+ btn.click(predict_single, inputs=image, outputs=[out_img, cat, fresh])
70
+
71
+
72
+ with gr.Tab("Live Webcam"):
73
+ webcam = gr.Image(sources=["webcam"], label="Webcam")
74
+ out_img = gr.Image()
75
+ cat = gr.Textbox(label="Category")
76
+ fresh = gr.Textbox(label="Freshness")
77
+ btn = gr.Button("Predict")
78
+ btn.click(predict_single, inputs=webcam, outputs=[out_img, cat, fresh])
79
+
80
+
81
+
82
+
83
+ if __name__ == "__main__":
84
+ demo.launch(server_name="0.0.0.0", server_port=7860)
85
+ >>>>>>> 5aa45b9f6ba9e1dc8b69f46c497abf68c7f09e73