Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
with open("img_id_to_info.json", "r") as f:
|
5 |
+
img_id_to_info = json.load(f)
|
6 |
+
|
7 |
+
def output_id_info(img_id):
|
8 |
+
if img_id is int:
|
9 |
+
img_id = str(img_id)
|
10 |
+
if img_id not in img_id_to_info.keys():
|
11 |
+
print("wrong")
|
12 |
+
return
|
13 |
+
this_info = img_id_to_info[img_id]
|
14 |
+
img_url = this_info['coco_url']
|
15 |
+
is_train = this_info['is_train']
|
16 |
+
caps = this_info['caps']
|
17 |
+
return img_url, is_train, [[cap] for cap in caps]
|
18 |
+
|
19 |
+
demo = gr.Interface(
|
20 |
+
title="COCO Information Retriever",
|
21 |
+
description="Given COCO Image ID, this app will give you the corresponding image, captions and place in the dataset.",
|
22 |
+
fn=output_id_info,
|
23 |
+
inputs=gr.Text(label="img_id"),
|
24 |
+
outputs=[
|
25 |
+
gr.Image(label="Img"),
|
26 |
+
gr.Checkbox(label="Is it in training set?"),
|
27 |
+
gr.DataFrame(
|
28 |
+
label="Caps",
|
29 |
+
headers=["Captions"],
|
30 |
+
datatype=['str'],
|
31 |
+
row_count=5,
|
32 |
+
col_count=1)
|
33 |
+
],
|
34 |
+
examples=['391895',
|
35 |
+
'522418',
|
36 |
+
'184613',
|
37 |
+
'318219',
|
38 |
+
'554625']
|
39 |
+
)
|
40 |
+
|
41 |
+
demo.launch()
|