manavshekar3340
commited on
Commit
•
40fdaeb
1
Parent(s):
58fdc79
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,30 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
# Load the pre-trained model from Hugging Face
|
4 |
model = gr.load("models/dima806/indian_food_image_detection")
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Create a Gradio interface with the custom title
|
7 |
iface = gr.Interface(
|
8 |
-
fn=
|
9 |
-
inputs=gr.Image(type="
|
10 |
-
outputs=
|
11 |
title="CAPSTONE",
|
12 |
-
description="Upload an image of Indian food to detect what it is."
|
|
|
13 |
)
|
14 |
|
15 |
# Launch the Gradio interface
|
16 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
|
5 |
# Load the pre-trained model from Hugging Face
|
6 |
model = gr.load("models/dima806/indian_food_image_detection")
|
7 |
|
8 |
+
def classify_image(image):
|
9 |
+
# Convert PIL image to the format expected by the model
|
10 |
+
image = Image.fromarray(image)
|
11 |
+
result = model(image)
|
12 |
+
|
13 |
+
# Parse the result to the format expected by Gradio's label component
|
14 |
+
predictions = result[0]["labels"] # Adjust this line based on the actual output structure
|
15 |
+
formatted_result = {pred["label"]: pred["score"] for pred in predictions}
|
16 |
+
|
17 |
+
return formatted_result
|
18 |
+
|
19 |
# Create a Gradio interface with the custom title
|
20 |
iface = gr.Interface(
|
21 |
+
fn=classify_image,
|
22 |
+
inputs=gr.Image(type="numpy"),
|
23 |
+
outputs=gr.Label(),
|
24 |
title="CAPSTONE",
|
25 |
+
description="Upload an image of Indian food to detect what it is.",
|
26 |
+
live=True # Enable live processing
|
27 |
)
|
28 |
|
29 |
# Launch the Gradio interface
|
30 |
+
iface.launch(share=True)
|