shyamgupta196 commited on
Commit
56473a6
1 Parent(s): 5081b4f

added model

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+ import torch
4
+ from timm import create_model
5
+ from timm import resolve_data_config
6
+ from timm.data.transforms_factory import create_transform
7
+
8
+ IMAGENET_1k_URL = "https://storage.googleapis.com/bit_models/ilsvrc2012_wordnet_lemmas.txt"
9
+ LABELS = requests.get()
10
+
11
+ model = create_model('resnet50',pretrained=True)
12
+ transform = create_transform(**resolve_data_config({},model=model))
13
+
14
+ model.eval()
15
+
16
+ def predict(img):
17
+ img = img.convert('RGB')
18
+ img = transform(img).unsqueeze(0)
19
+ with torch.no_grad():
20
+ out= model(img)
21
+ probability = torch.nn.functional.softmax(out[0],dim=0)
22
+
23
+ values, indices = torch.topk(probability,k=5)
24
+ return {LABELS[i]: v.items() for i,v in zip(indices,values)}
25
+
26
+
27
+ iface = gr.Interface(fn=predict, inputs=gr.inputs.Image(type='pil'), outputs="label").launch()
28
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ timm
2
+ gradio