Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from transformers import AutoModelForImageClassification,
|
4 |
from PIL import Image
|
5 |
import torch
|
6 |
|
7 |
-
# Menginisialisasi model dan
|
8 |
-
model_name = "ahmadalfian/fruits_vegetables_classifier"
|
9 |
model = AutoModelForImageClassification.from_pretrained(model_name)
|
10 |
-
|
11 |
|
12 |
# Fungsi untuk memprediksi kelas
|
13 |
def predict(image):
|
14 |
-
|
15 |
-
inputs =
|
16 |
with torch.no_grad():
|
17 |
outputs = model(**inputs)
|
18 |
predictions = outputs.logits.argmax(dim=1)
|
@@ -98,5 +98,4 @@ iface = gr.Interface(
|
|
98 |
description="Upload an image of a fruit or vegetable to classify and get its nutritional information."
|
99 |
)
|
100 |
|
101 |
-
|
102 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
|
4 |
from PIL import Image
|
5 |
import torch
|
6 |
|
7 |
+
# Menginisialisasi model dan feature extractor dari Hugging Face
|
8 |
+
model_name = "ahmadalfian/fruits_vegetables_classifier"
|
9 |
model = AutoModelForImageClassification.from_pretrained(model_name)
|
10 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
11 |
|
12 |
# Fungsi untuk memprediksi kelas
|
13 |
def predict(image):
|
14 |
+
# Preprocess gambar menggunakan feature extractor
|
15 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
16 |
with torch.no_grad():
|
17 |
outputs = model(**inputs)
|
18 |
predictions = outputs.logits.argmax(dim=1)
|
|
|
98 |
description="Upload an image of a fruit or vegetable to classify and get its nutritional information."
|
99 |
)
|
100 |
|
|
|
101 |
iface.launch()
|