manavshekar3340
commited on
Commit
•
bd6c370
1
Parent(s):
40fdaeb
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
-
import
|
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 |
-
#
|
10 |
-
image
|
|
|
11 |
result = model(image)
|
12 |
|
13 |
# Parse the result to the format expected by Gradio's label component
|
14 |
-
predictions = result[0]
|
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(
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
+
import numpy as np
|
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 |
+
# Ensure the image is in the correct format for the model
|
10 |
+
if isinstance(image, np.ndarray):
|
11 |
+
image = Image.fromarray(image)
|
12 |
result = model(image)
|
13 |
|
14 |
# Parse the result to the format expected by Gradio's label component
|
15 |
+
predictions = result[0] # Adjust this line based on the actual output structure
|
16 |
formatted_result = {pred["label"]: pred["score"] for pred in predictions}
|
17 |
+
|
18 |
return formatted_result
|
19 |
|
20 |
# Create a Gradio interface with the custom title
|
21 |
iface = gr.Interface(
|
22 |
fn=classify_image,
|
23 |
+
inputs=gr.Image(type="numpy", label="Upload an image"),
|
24 |
+
outputs=gr.Label(label="Prediction"),
|
25 |
title="CAPSTONE",
|
26 |
+
description="Upload an image of Indian food to detect what it is."
|
|
|
27 |
)
|
28 |
|
29 |
# Launch the Gradio interface
|
30 |
+
iface.launch()
|