Destrobot commited on
Commit
9f6857c
·
verified ·
1 Parent(s): 5426da5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -8
app.py CHANGED
@@ -1,17 +1,13 @@
1
  import gradio as gr
2
  import torch
3
- from transformers import AutoImageProcessor, AutoModelForImageClassification
4
 
5
  model_id = "SABR22/food_models"
6
- processor = AutoImageProcessor.from_pretrained(model_id)
7
- model = AutoModelForImageClassification.from_pretrained(model_id)
8
 
9
  def classify_food(image):
10
- inputs = processor(images=image, return_tensors="pt")
11
- outputs = model(**inputs)
12
- logits = outputs.logits
13
- predicted_class_idx = logits.argmax(-1).item()
14
- return model.config.id2label[predicted_class_idx]
15
 
16
  interface = gr.Interface(
17
  fn=classify_food,
 
1
  import gradio as gr
2
  import torch
3
+ from transformers import pipeline
4
 
5
  model_id = "SABR22/food_models"
6
+ pipe = pipeline("image-classification", model="SABR22/food_models")
 
7
 
8
  def classify_food(image):
9
+ image = pipe(image)
10
+ return image[0]['label']
 
 
 
11
 
12
  interface = gr.Interface(
13
  fn=classify_food,