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