Spaces:
Runtime error
Runtime error
Commit
·
5fc084e
1
Parent(s):
5577db9
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install transformers
|
2 |
+
!pip install gradio
|
3 |
+
|
4 |
+
from transformers import AutoImageProcessor
|
5 |
+
from transformers import TFAutoModelForImageClassification
|
6 |
+
import tensorflow as tf
|
7 |
+
|
8 |
+
def classifier(image):
|
9 |
+
image_processor = AutoImageProcessor.from_pretrained("ZachBeesley/Food-Classifier")
|
10 |
+
inputs = image_processor(image, return_tensors="tf")
|
11 |
+
model = TFAutoModelForImageClassification.from_pretrained("ZachBeesley/Food-Classifier")
|
12 |
+
logits = model(**inputs).logits
|
13 |
+
predicted_class_id = int(tf.math.argmax(logits, axis=-1)[0])
|
14 |
+
return model.config.id2label[predicted_class_id]
|
15 |
+
|
16 |
+
import gradio as gr
|
17 |
+
|
18 |
+
|
19 |
+
demo = gr.Interface(fn=classifier, inputs="image", outputs="label")
|
20 |
+
demo.launch()
|