rgny commited on
Commit
6c04404
·
verified ·
1 Parent(s): 3a90c4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -27
app.py CHANGED
@@ -1,27 +1,28 @@
1
- import gradio as gr
2
- import torch
3
- import torchvision
4
- from model import create_model
5
- from timeit import default_timer as timer
6
-
7
- model,transform=create_model()
8
- model.load_state_dict(torch.load("deneme_modeli.pth"))
9
- class_names = ["pizza","steak","sushi"]
10
- def predict(model,image):
11
- start=timer()
12
- image=transform(image.to("cpu")).unsqueeze(0)
13
- model=model.to("cpu")
14
- pred=model(image)
15
- pred = {class_names[i]:torch.softmax(pred)[0][i] for i in range(3)}
16
- td=timer()-start
17
- return pred,td
18
-
19
- inputs = gr.Image(type="pil", label = "Resim")
20
- outputs = [gr.Label(num_top_classes=3,label="Tahminler"),gr.Number(label="Süre")]
21
- demo=gr.Interface(fn = predict,
22
- inputs=inputs,
23
- outputs=outputs,
24
- examples=["examples/673127.jpg","examples/690177.jpg"],
25
- title="Yeni Model")
26
-
27
- demo.launch()
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import torchvision
4
+ from model import create_model
5
+ from timeit import default_timer as timer
6
+
7
+ model,transform=create_model()
8
+ model=model.to("cpu")
9
+ model.load_state_dict(torch.load("deneme_modeli.pth").to("cpu"))
10
+ class_names = ["pizza","steak","sushi"]
11
+ def predict(model,image):
12
+ start=timer()
13
+ image=transform(image.to("cpu")).unsqueeze(0)
14
+ model=model.to("cpu")
15
+ pred=model(image)
16
+ pred = {class_names[i]:torch.softmax(pred)[0][i] for i in range(3)}
17
+ td=timer()-start
18
+ return pred,td
19
+
20
+ inputs = gr.Image(type="pil", label = "Resim")
21
+ outputs = [gr.Label(num_top_classes=3,label="Tahminler"),gr.Number(label="Süre")]
22
+ demo=gr.Interface(fn = predict,
23
+ inputs=inputs,
24
+ outputs=outputs,
25
+ examples=["examples/673127.jpg","examples/690177.jpg"],
26
+ title="Yeni Model")
27
+
28
+ demo.launch()