Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,10 @@ feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
|
|
| 10 |
|
| 11 |
# Define the prediction function
|
| 12 |
def classify_image(img):
|
|
|
|
| 13 |
inputs = feature_extractor(images=img, return_tensors="pt")
|
|
|
|
|
|
|
| 14 |
with torch.no_grad():
|
| 15 |
outputs = model(**inputs)
|
| 16 |
probs = torch.softmax(outputs.logits, dim=-1)
|
|
@@ -22,8 +25,8 @@ def classify_image(img):
|
|
| 22 |
# Create the Gradio interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=classify_image,
|
| 25 |
-
inputs=gr.Image(type="pil"),
|
| 26 |
-
outputs="text",
|
| 27 |
title="Food Image Classification",
|
| 28 |
description="Upload an image to classify if it’s an apple pie, etc."
|
| 29 |
)
|
|
|
|
| 10 |
|
| 11 |
# Define the prediction function
|
| 12 |
def classify_image(img):
|
| 13 |
+
# Preprocess the image and extract features
|
| 14 |
inputs = feature_extractor(images=img, return_tensors="pt")
|
| 15 |
+
|
| 16 |
+
# Run the model in evaluation mode
|
| 17 |
with torch.no_grad():
|
| 18 |
outputs = model(**inputs)
|
| 19 |
probs = torch.softmax(outputs.logits, dim=-1)
|
|
|
|
| 25 |
# Create the Gradio interface
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=classify_image,
|
| 28 |
+
inputs=gr.Image(type="pil"), # Image input type as PIL (Pillow Image)
|
| 29 |
+
outputs="text", # Text output will display the predicted label
|
| 30 |
title="Food Image Classification",
|
| 31 |
description="Upload an image to classify if it’s an apple pie, etc."
|
| 32 |
)
|