ehsk commited on
Commit
cb8d1a9
·
1 Parent(s): 464ee69

initial commit

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import requests
3
+ import gradio as gr
4
+
5
+ # Load the JSON data once at startup
6
+ URL = "https://github.com/THU-KEG/AgentIF/raw/refs/heads/main/data/eval.json"
7
+ response = requests.get(URL)
8
+ data = response.json()
9
+
10
+
11
+ def format_input(input_list):
12
+ if not isinstance(input_list, list):
13
+ return "Invalid format for 'input' field."
14
+ formatted = []
15
+ for msg in input_list:
16
+ role = msg.get("role", "unknown").capitalize()
17
+ content = msg.get("content", "").strip()
18
+ block = f"### {role}:\n```\n{content}\n```"
19
+ formatted.append(block)
20
+ return "\n\n".join(formatted)
21
+
22
+
23
+ def get_entry(index):
24
+ try:
25
+ index = int(index)
26
+ if index < 0 or index >= len(data):
27
+ return f"Index {index} out of range.", "", ""
28
+
29
+ entry = data[index]
30
+ entry_type = entry.get("type", "")
31
+
32
+ # Prepare input
33
+ input_formatted = format_input(entry.get("input", []))
34
+
35
+ # Raw data excluding exec, output, and input
36
+ raw_data = json.dumps(entry, indent=2, ensure_ascii=False)
37
+
38
+ print(f"Showing entry {index}: {entry_type}")
39
+
40
+ return f"Showing entry {index}", input_formatted, raw_data
41
+
42
+ except ValueError:
43
+ return "Please enter a valid integer index.", "", ""
44
+
45
+
46
+ with gr.Blocks(title="AgentIF Viewer") as demo:
47
+ gr.Markdown("# AgentIF Viewer")
48
+ gr.Markdown(f"🔍 [AgentIF](https://arxiv.org/abs/2505.16944) contains examples in **both English and Chinese**. Use the index below to browse them.")
49
+
50
+
51
+ index_range = f"[0, {len(data)})"
52
+ index_input = gr.Textbox(
53
+ label="Enter Index",
54
+ value="100",
55
+ info=f"Valid range: {index_range}",
56
+ placeholder="Enter an integer index"
57
+ )
58
+ status_output = gr.Textbox(label="Status", lines=1)
59
+ input_md = gr.Markdown(label="Input")
60
+
61
+ with gr.Accordion("Raw Data", open=False):
62
+ raw_data = gr.Code(label="Raw JSON (excluding input/output/exec)", language="json")
63
+
64
+ index_input.change(fn=get_entry, inputs=index_input, outputs=[status_output, input_md, raw_data])
65
+
66
+ demo.load(fn=lambda: get_entry("100"), outputs=[
67
+ status_output, input_md, raw_data
68
+ ])
69
+
70
+
71
+ if __name__ == "__main__":
72
+ demo.launch()