abidlabs HF staff commited on
Commit
246ce57
1 Parent(s): d6891e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -1,28 +1,22 @@
1
- import torch
2
-
3
- model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
4
-
5
  import requests
6
- from PIL import Image
7
- from torchvision import transforms
 
8
 
9
- # Download human-readable labels for ImageNet.
10
- response = requests.get("https://git.io/JJkYN")
11
- labels = response.text.split("\n")
12
 
13
- def predict(inp):
14
- inp = Image.fromarray(inp.astype('uint8'), 'RGB')
15
- inp = transforms.ToTensor()(inp).unsqueeze(0)
16
- with torch.no_grad():
17
- prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
18
- confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
19
  return confidences
 
20
 
21
  import gradio as gr
22
 
23
  gr.Interface(fn=predict,
24
- inputs="image",
25
  outputs=gr.outputs.Label(num_top_classes=3),
26
- examples=["lion.jpg", "cheetah.jpg"],
27
  theme="default",
28
  css=".footer{display:none !important}").launch()
 
 
 
 
 
1
  import requests
2
+ import tensorflow as tf
3
+
4
+ inception_net = tf.keras.applications.MobileNetV2()
5
 
 
 
 
6
 
7
+ def classify_image(inp):
8
+ inp = inp.reshape((-1, 224, 224, 3))
9
+ inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
10
+ prediction = inception_net.predict(inp).flatten()
11
+ confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
 
12
  return confidences
13
+
14
 
15
  import gradio as gr
16
 
17
  gr.Interface(fn=predict,
18
+ inputs=gr.inputs.Image(shape=(224, 224)),
19
  outputs=gr.outputs.Label(num_top_classes=3),
20
+ examples=["banana.jpg", "car.jpg"]).launch(),
21
  theme="default",
22
  css=".footer{display:none !important}").launch()