Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,27 +2,22 @@ from transformers import AutoFeatureExtractor, RegNetForImageClassification
|
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
model = RegNetForImageClassification.from_pretrained("facebook/regnet-y-040")
|
8 |
-
|
9 |
-
def inference(image):
|
10 |
-
print("Type of image", type(image))
|
11 |
-
inputs = feature_extractor(image, return_tensors="pt")
|
12 |
-
|
13 |
-
with torch.no_grad():
|
14 |
-
logits = model(**inputs).logits
|
15 |
-
|
16 |
-
predicted_label = logits.argmax(-1).item()
|
17 |
-
return model.config.id2label[predicted_label]
|
18 |
-
|
19 |
-
title="RegNet-image-classification"
|
20 |
-
description="This space uses RegNet Model with an image classification head on top (a linear layer on top of the pooled features). It predicts one of the 1000 ImageNet classes. Check [Docs](https://huggingface.co/docs/transformers/main/en/model_doc/regnet) for more details."
|
21 |
-
|
22 |
-
examples=[['wolf.jpg'], ['ballon.jpg'], ['fountain.jpg']]
|
23 |
-
iface = gr.Interface(inference, inputs=gr.inpu, outputs="text",title=title,description=description,examples=examples)
|
24 |
-
iface.launch(enable_queue=True,cache_examples=True)
|
25 |
|
26 |
-
|
27 |
-
print("
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
|
5 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/regnet-y-040")
|
6 |
+
model = RegNetForImageClassification.from_pretrained("facebook/regnet-y-040")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def inference(image):
|
9 |
+
print("Type of image", type(image))
|
10 |
+
inputs = feature_extractor(image, return_tensors="pt")
|
11 |
+
|
12 |
+
with torch.no_grad():
|
13 |
+
logits = model(**inputs).logits
|
14 |
+
|
15 |
+
predicted_label = logits.argmax(-1).item()
|
16 |
+
return model.config.id2label[predicted_label]
|
17 |
+
|
18 |
+
title="RegNet-image-classification"
|
19 |
+
description="This space uses RegNet Model with an image classification head on top (a linear layer on top of the pooled features). It predicts one of the 1000 ImageNet classes. Check [Docs](https://huggingface.co/docs/transformers/main/en/model_doc/regnet) for more details."
|
20 |
+
|
21 |
+
examples=[['wolf.jpg'], ['ballon.jpg'], ['fountain.jpg']]
|
22 |
+
iface = gr.Interface(inference, inputs=gr.inputs.Image(), outputs="text",title=title,description=description,examples=examples)
|
23 |
+
iface.launch(enable_queue=True)
|