import gradio as gr import torch import torchvision from model import create_model from timeit import default_timer as timer model,transform=create_model() model=model.to("cpu") model.load_state_dict(torch.load("deneme_modeli.pth").to("cpu")) class_names = ["pizza","steak","sushi"] def predict(model,image): start=timer() image=transform(image.to("cpu")).unsqueeze(0) model=model.to("cpu") pred=model(image) pred = {class_names[i]:torch.softmax(pred)[0][i] for i in range(3)} td=timer()-start return pred,td inputs = gr.Image(type="pil", label = "Resim") outputs = [gr.Label(num_top_classes=3,label="Tahminler"),gr.Number(label="Süre")] demo=gr.Interface(fn = predict, inputs=inputs, outputs=outputs, examples=["examples/673127.jpg","examples/690177.jpg"], title="Yeni Model") demo.launch()