Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
import torch
|
|
|
4 |
from transformers import ViTImageProcessor,pipeline
|
5 |
|
6 |
model = ViTImageProcessor.from_pretrained('SeyedAli/Food-Image-Classification-VIT')
|
7 |
|
8 |
def FoodClassification(image):
|
|
|
9 |
# Encode your PIL Image as a JPEG without writing to disk
|
10 |
-
buffer = io.BytesIO(image)
|
11 |
-
YourImage.save(buffer, format='JPEG', quality=75)
|
12 |
|
13 |
-
# You probably want
|
14 |
-
desiredObject = buffer.getbuffer()
|
15 |
|
16 |
pipline = pipeline(task="image-classification", model=model)
|
17 |
-
output=pipline(model(Image.open(desiredObject), return_tensors='pt'))
|
|
|
18 |
return output
|
19 |
|
20 |
iface = gr.Interface(fn=FoodClassification, inputs="image", outputs="text")
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
+
from torchvision.io import read_image
|
5 |
from transformers import ViTImageProcessor,pipeline
|
6 |
|
7 |
model = ViTImageProcessor.from_pretrained('SeyedAli/Food-Image-Classification-VIT')
|
8 |
|
9 |
def FoodClassification(image):
|
10 |
+
image = read_image(image)
|
11 |
# Encode your PIL Image as a JPEG without writing to disk
|
12 |
+
# buffer = io.BytesIO(image)
|
13 |
+
# YourImage.save(buffer, format='JPEG', quality=75)
|
14 |
|
15 |
+
# # You probably want
|
16 |
+
# desiredObject = buffer.getbuffer()
|
17 |
|
18 |
pipline = pipeline(task="image-classification", model=model)
|
19 |
+
#output=pipline(model(Image.open(desiredObject), return_tensors='pt'))
|
20 |
+
output=pipline(image, return_tensors='pt'))
|
21 |
return output
|
22 |
|
23 |
iface = gr.Interface(fn=FoodClassification, inputs="image", outputs="text")
|