akansha2k2 commited on
Commit
f3616e1
1 Parent(s): acfceff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -1,15 +1,29 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- pipeline = pipeline(task="image-classification", model="akansha2k2/Burger_sandwich_pizza")
 
5
 
6
- def predict(image):
7
- predictions = pipeline(image)
8
- return {p["label"]: p["score"] for p in predictions}
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  gr.Interface(
11
  predict,
12
- inputs=gr.Image(label="Upload junk food (sandwich,pizza,burgur) candidate", type="filepath"),
13
- outputs=gr.Label(num_top_classes=2),
14
- title="pizza or burgur or sandwich?",
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()