fvde commited on
Commit
4bf8dd9
·
1 Parent(s): 4385e0f

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +31 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import requests
4
+ import os
5
+ from torchvision import transforms
6
+
7
+ model = torch.hub.load("pytorch/vision:v0.6.0", "resnet18", pretrained=True).eval()
8
+ response = requests.get("https://git.io/JJkYN")
9
+ labels = response.text.split("\n")
10
+
11
+
12
+ def predict(inp):
13
+ inp = transforms.ToTensor()(inp).unsqueeze(0)
14
+ with torch.no_grad():
15
+ prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
16
+ confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
17
+ return confidences
18
+
19
+
20
+ demo = gr.Interface(
21
+ fn=predict,
22
+ inputs=gr.inputs.Image(type="pil"),
23
+ outputs=gr.outputs.Label(num_top_classes=3),
24
+ examples=[],
25
+ )
26
+
27
+ basic_auth = (
28
+ "lenox",
29
+ os.environ["PROTOTYPE_PASSWORD"],
30
+ ) # gets os.environ["PROTOTYPE_PASSWORD"] from hg repo secrets
31
+ demo.launch(auth=basic_auth)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==3.40.1
2
+ torch==2.0.1
3
+ torchvision==0.15.2
4
+ huggingface-hub==0.16.4