satpalsr commited on
Commit
73dfc5e
1 Parent(s): d832e1f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoFeatureExtractor, RegNetForImageClassification
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)