Update app.py
Browse files
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.
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
pred
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
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()
|