Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,14 +5,15 @@ import torch
|
|
5 |
from torchvision.io import read_image
|
6 |
from transformers import ViTForImageClassification, ViTFeatureExtractor,ViTImageProcessor,pipeline
|
7 |
|
|
|
8 |
# model = ViTImageProcessor.from_pretrained('SeyedAli/Food-Image-Classification-VIT')
|
|
|
9 |
model = ViTForImageClassification.from_pretrained('SeyedAli/Food-Image-Classification-VIT')
|
10 |
feature_extractor = ViTFeatureExtractor.from_pretrained('SeyedAli/Food-Image-Classification-VIT')
|
|
|
11 |
def FoodClassification(image):
|
12 |
with tempfile.NamedTemporaryFile(suffix=".png") as temp_image_file:
|
13 |
# Copy the contents of the uploaded image file to the temporary file
|
14 |
-
# temp_image_file.write(open(image, "rb").read())
|
15 |
-
# temp_image_file.flush()
|
16 |
Image.fromarray(image).save(temp_image_file.name)
|
17 |
# Load the image file using torchvision
|
18 |
image = read_image(temp_image_file.name)
|
|
|
5 |
from torchvision.io import read_image
|
6 |
from transformers import ViTForImageClassification, ViTFeatureExtractor,ViTImageProcessor,pipeline
|
7 |
|
8 |
+
# With ViTImageProcessor we can't use pipeline for image classification so Icomment it
|
9 |
# model = ViTImageProcessor.from_pretrained('SeyedAli/Food-Image-Classification-VIT')
|
10 |
+
|
11 |
model = ViTForImageClassification.from_pretrained('SeyedAli/Food-Image-Classification-VIT')
|
12 |
feature_extractor = ViTFeatureExtractor.from_pretrained('SeyedAli/Food-Image-Classification-VIT')
|
13 |
+
|
14 |
def FoodClassification(image):
|
15 |
with tempfile.NamedTemporaryFile(suffix=".png") as temp_image_file:
|
16 |
# Copy the contents of the uploaded image file to the temporary file
|
|
|
|
|
17 |
Image.fromarray(image).save(temp_image_file.name)
|
18 |
# Load the image file using torchvision
|
19 |
image = read_image(temp_image_file.name)
|