wangerniu commited on
Commit
be9e785
·
1 Parent(s): b5db0fe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import gradio as gr
4
+ import torch
5
+ from torchvision import transforms
6
+ import requests
7
+ from PIL import Image
8
+
9
+
10
+ model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
11
+ #标题
12
+ title = "抽取式问答"
13
+ #标题下的描述,支持md格式
14
+ description = "输入上下文与问题后,点击submit按钮,可从上下文中抽取出答案,赶快试试吧!"
15
+
16
+ # Download human-readable labels for ImageNet.
17
+ # response = requests.get("http://git.io/JJkYN")
18
+ # labels = response.text.split("\n")
19
+ # 打开文件
20
+ file = open('gradio/label.txt', 'r')
21
+ # 读取文件内容
22
+ labels = file.readlines()
23
+ def to_black(inp,long,lat,Area):
24
+ inp = Image.fromarray(inp.astype('uint8'), 'RGB')
25
+ inp = transforms.ToTensor()(inp).unsqueeze(0)
26
+ with torch.no_grad():
27
+ prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
28
+ return {labels[i]: float(prediction[i]) for i in range(1000)}
29
+
30
+ outputs = gr.outputs.Label(num_top_classes=3)
31
+ interface = gr.Interface(fn=to_black,
32
+ inputs=["image",
33
+ gr.Number(label="longitude"),
34
+ gr.Number(label="latitude"),
35
+ gr.Slider(256, 512,label='Area')],
36
+ outputs=outputs,
37
+ title=title,
38
+ description=description,
39
+ examples=[["gradio/未命名1688700109.png",70.1,40.0,256]])
40
+ interface.launch()