abnordist commited on
Commit
72751df
Β·
1 Parent(s): 5ea4026

fast food app launch

Browse files
Files changed (2) hide show
  1. app.py +46 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import torch.nn as nn
4
+ from torchvision import models, transforms
5
+
6
+
7
+
8
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
9
+
10
+ class_names = [
11
+ 'Baked Potato',
12
+ 'Burger',
13
+ 'Crispy Chicken',
14
+ 'Donut',
15
+ 'Fries',
16
+ 'Hot Dog',
17
+ 'Pizza',
18
+ 'Sandwich',
19
+ 'Taco',
20
+ 'Taquito'
21
+ ]
22
+
23
+ model = models.resnet18(pretrained=True)
24
+ num_features = model.fc.in_features
25
+ model.fc = nn.Linear(num_features, len(class_names))
26
+
27
+ # model = model.to(device)
28
+ # load model from ./models
29
+ model.load_state_dict(torch.load("models/model_resNet18_1.pth"))
30
+ model.eval()
31
+
32
+ def predict(inp):
33
+ inp = transforms.ToTensor()(inp).unsqueeze(0)
34
+ with torch.no_grad():
35
+ prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
36
+ confidences = {class_names[i]: float(prediction[i]) for i in range(len(class_names))}
37
+ return confidences
38
+
39
+ app = gr.Interface(
40
+ fn=predict,
41
+ inputs=gr.Image(type="pil"),
42
+ outputs=gr.Label(num_top_classes=10)
43
+ )
44
+
45
+ # display the app
46
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ torch=1.13.0