Spaces:
Runtime error
Runtime error
Commit
•
f3616e1
1
Parent(s):
acfceff
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
|
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
-
def predict(
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
gr.Interface(
|
11 |
predict,
|
12 |
-
inputs=gr.Image(label="Upload junk food (sandwich,pizza,
|
13 |
-
outputs=gr.Label(num_top_classes=
|
14 |
-
title="
|
15 |
-
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
import torch
|
4 |
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("akhooli/mistral-7B-llm")
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained("akhooli/mistral-7B-llm")
|
7 |
|
8 |
+
def predict(image_path):
|
9 |
+
# Load and preprocess the image
|
10 |
+
with open(image_path, "rb") as f:
|
11 |
+
image_bytes = f.read()
|
12 |
+
|
13 |
+
# Tokenize and predict
|
14 |
+
inputs = tokenizer(image_bytes, return_tensors="pt", padding=True, truncation=True)
|
15 |
+
outputs = model(**inputs)
|
16 |
+
predicted_class_idx = torch.argmax(outputs.logits)
|
17 |
+
|
18 |
+
# In this example, we are assuming the labels are ['pizza', 'burger', 'sandwich']
|
19 |
+
labels = ['pizza', 'burger', 'sandwich']
|
20 |
+
predicted_label = labels[predicted_class_idx]
|
21 |
+
|
22 |
+
return predicted_label
|
23 |
|
24 |
gr.Interface(
|
25 |
predict,
|
26 |
+
inputs=gr.Image(label="Upload junk food (sandwich, pizza, burger) candidate", type="file"),
|
27 |
+
outputs=gr.Label(num_top_classes=3),
|
28 |
+
title="Pizza, Burger, or Sandwich?",
|
29 |
+
).launch()
|