| | import gradio as gr |
| | import cv2 |
| | import gradio as gr |
| | import torch |
| | from torchvision import transforms |
| | import requests |
| | from PIL import Image |
| |
|
| |
|
| | model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval() |
| | |
| | title = "抽取式问答" |
| | |
| | description = "输入上下文与问题后,点击submit按钮,可从上下文中抽取出答案,赶快试试吧!" |
| |
|
| | |
| | |
| | |
| | |
| | file = open('label.txt', 'r') |
| | |
| | labels = file.readlines() |
| | def to_black(inp,long,lat,Area): |
| | inp = Image.fromarray(inp.astype('uint8'), 'RGB') |
| | inp = transforms.ToTensor()(inp).unsqueeze(0) |
| | with torch.no_grad(): |
| | prediction = torch.nn.functional.softmax(model(inp)[0], dim=0) |
| | return {labels[i]: float(prediction[i]) for i in range(1000)} |
| |
|
| | outputs = gr.outputs.Label(num_top_classes=3) |
| | interface = gr.Interface(fn=to_black, |
| | inputs=["image", |
| | gr.Number(label="longitude"), |
| | gr.Number(label="latitude"), |
| | gr.Slider(256, 512,label='Area')], |
| | outputs=outputs, |
| | title=title, |
| | description=description, |
| | examples=[["cat_dog.png",70.1,40.0,256]]) |
| | interface.launch() |