bstraehle commited on
Commit
f04302b
·
verified ·
1 Parent(s): 0eb6fa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -200
app.py CHANGED
@@ -1,212 +1,113 @@
1
- # References:
2
-
3
- # https://www.gradio.app/guides/quickstart
4
-
5
- import os
6
- import gradio as gr
7
- from agents.crew import run_crew
8
- from utils.utils import get_questions
9
-
10
- # Initialization
11
-
12
- QUESTION_FILE_PATH_GAIA = "files/gaia_validation.jsonl"
13
- QUESTION_FILE_PATH_HLE = "files/hle_validation.jsonl"
14
-
15
- DEFAULT_QUESTION = "In MCP's 1st Birthday Hackathon, hosted by Anthropic and Gradio, what percentage of participants submitted a solution so far?"
16
-
17
- # MCP server functions
18
-
19
- def ask(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name = ""):
20
- """
21
- Ask General AI Assistant a question to answer.
22
-
23
- Args:
24
- question (str): The question to answer
25
- openai_api_key (str): OpenAI API key
26
- gemini_api_key (str): Gemini API key
27
- anthropic_api_key (str): Anthropic API key
28
- file_name (str): Optional file name
29
-
30
- Returns:
31
- str: The answer to the question
32
- """
33
- if not question:
34
- gr.Warning("Question is required.")
35
- return ""
36
-
37
- if not openai_api_key:
38
- gr.Warning("OpenAI API Key is required.")
39
- return ""
40
-
41
- if not gemini_api_key:
42
- gr.Warning("Gemini API Key is required.")
43
- return ""
44
-
45
- if not anthropic_api_key:
46
- gr.Warning("Anthropic API Key is required.")
47
- return ""
48
-
49
- if file_name:
50
- file_name = f"files/{file_name}"
51
-
52
- try:
53
- os.environ["OPENAI_API_KEY"] = openai_api_key
54
- os.environ["GEMINI_API_KEY"] = gemini_api_key
55
- os.environ["MODEL_API_KEY"] = anthropic_api_key
56
-
57
- return run_crew(question, file_name)
58
- except Exception as e:
59
- gr.Warning(str(e))
60
- return ""
61
- finally:
62
- for key in ["OPENAI_API_KEY", "GEMINI_API_KEY", "MODEL_API_KEY"]:
63
- os.environ.pop(key, None)
64
-
65
- # Helper functions
66
-
67
- def update_file_link(file_name):
68
- if file_name:
69
- space_id = os.environ.get("SPACE_ID", "bstraehle/gaia")
70
- base_url = f"https://huggingface.co/spaces/{space_id}/blob/main/files"
71
- return f'<a href="{base_url}/{file_name}" target="_blank">Open File</a>'
72
-
73
- return ""
74
-
75
- # Graphical user interface
76
-
77
- CSS_FULL_WIDTH = """
78
- body {
79
- margin: 0 !important;
80
- }
81
- .gradio-container {
82
- max-width: 100% !important;
83
- width: 100% !important;
84
- margin: 0 !important;
85
- padding-left: 0 !important;
86
- padding-right: 0 !important;
87
- }
88
- .content-padding {
89
- padding-left: 1.5rem;
90
- padding-right: 1.5rem;
91
- }
92
- .full-width-tabs {
93
- width: 100%;
94
- }
95
- .full-width-tabs .gradio-block {
96
- max-width: 100%;
97
- width: 100%;
98
- }
99
- """
100
-
101
  with gr.Blocks() as gaia:
102
  gr.HTML(f"<style>{CSS_FULL_WIDTH}</style>")
103
-
104
- gr.Markdown("## General AI Assistant")
105
 
106
- gr.Markdown(os.environ.get("DESCRIPTION"))
107
-
108
- with gr.Row():
109
- with gr.Column(scale=3):
110
- with gr.Row():
111
- question = gr.Textbox(
112
- label="Question *",
113
- placeholder=DEFAULT_QUESTION,
114
- interactive=True,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  lines=1,
116
  max_lines=3
117
  )
118
- with gr.Row():
119
- ground_truth = gr.Textbox(
120
- label="Ground Truth",
121
- interactive=True,
122
- lines=1,
123
- max_lines=2
124
- )
125
- file_name = gr.Textbox(
126
- label="File Name",
127
- interactive=True,
128
- scale=2,
129
- lines=1,
130
- max_lines=2
131
- )
132
- file_link = gr.HTML(
133
- label="File Link",
134
- value=""
135
- )
136
- with gr.Row():
137
- openai_api_key = gr.Textbox(
138
- label="OpenAI API Key *",
139
- type="password",
140
- placeholder="sk‑...",
141
- interactive=True
142
- )
143
- gemini_api_key = gr.Textbox(
144
- label="Gemini API Key *",
145
- type="password",
146
- interactive=True
147
- )
148
- anthropic_api_key = gr.Textbox(
149
- label="Anthropic API Key *",
150
- type="password",
151
- placeholder="sk-ant-...",
152
- interactive=True
153
- )
154
- with gr.Row():
155
- clear_btn = gr.ClearButton(
156
- components=[question, ground_truth, file_name, file_link]
157
- )
158
- submit_btn = gr.Button("Submit", variant="primary")
159
- with gr.Column(scale=1):
160
- answer = gr.Textbox(
161
- label="Answer",
162
- interactive=False,
163
- lines=1,
164
- max_lines=3
165
- )
166
-
167
- submit_btn.click(
168
- fn=ask,
169
- inputs=[question, openai_api_key, gemini_api_key, anthropic_api_key, file_name],
170
- outputs=answer
171
- )
172
-
173
- file_name.change(
174
- fn=update_file_link,
175
- inputs=[file_name],
176
- outputs=[file_link]
177
- )
178
 
179
- with gr.Tabs():
180
- with gr.TabItem("GAIA Benchmark Level 1"):
181
- gr.Examples(
182
- examples=get_questions(QUESTION_FILE_PATH_GAIA, 1),
183
- inputs=[question, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
184
- examples_per_page=3,
185
- cache_examples=False
186
- )
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
- with gr.TabItem("GAIA Benchmark Level 2"):
189
- gr.Examples(
190
- examples=get_questions(QUESTION_FILE_PATH_GAIA, 2),
191
- inputs=[question, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
192
- examples_per_page=3,
193
- cache_examples=False
194
- )
195
 
196
- with gr.TabItem("GAIA Benchmark Level 3"):
197
- gr.Examples(
198
- examples=get_questions(QUESTION_FILE_PATH_GAIA, 3),
199
- inputs=[question, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
200
- examples_per_page=3,
201
- cache_examples=False
202
- )
203
 
204
- with gr.TabItem("Humanity's Last Exam"):
205
- gr.Examples(
206
- examples=get_questions(QUESTION_FILE_PATH_HLE, 0),
207
- inputs=[question, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
208
- examples_per_page=3,
209
- cache_examples=False
210
- )
211
 
212
  gaia.launch(mcp_server=True, share=False, ssr_mode=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  with gr.Blocks() as gaia:
2
  gr.HTML(f"<style>{CSS_FULL_WIDTH}</style>")
 
 
3
 
4
+ with gr.Column(elem_classes=["content-padding"]):
5
+ gr.Markdown("## General AI Assistant")
6
+
7
+ gr.Markdown(os.environ.get("DESCRIPTION"))
8
+
9
+ with gr.Row():
10
+ with gr.Column(scale=3):
11
+ with gr.Row():
12
+ question = gr.Textbox(
13
+ label="Question *",
14
+ placeholder=DEFAULT_QUESTION,
15
+ interactive=True,
16
+ lines=1,
17
+ max_lines=3
18
+ )
19
+ with gr.Row():
20
+ ground_truth = gr.Textbox(
21
+ label="Ground Truth",
22
+ interactive=True,
23
+ lines=1,
24
+ max_lines=2
25
+ )
26
+ file_name = gr.Textbox(
27
+ label="File Name",
28
+ interactive=True,
29
+ scale=2,
30
+ lines=1,
31
+ max_lines=2
32
+ )
33
+ file_link = gr.HTML(
34
+ label="File Link",
35
+ value=""
36
+ )
37
+ with gr.Row():
38
+ openai_api_key = gr.Textbox(
39
+ label="OpenAI API Key *",
40
+ type="password",
41
+ placeholder="sk‑...",
42
+ interactive=True
43
+ )
44
+ gemini_api_key = gr.Textbox(
45
+ label="Gemini API Key *",
46
+ type="password",
47
+ interactive=True
48
+ )
49
+ anthropic_api_key = gr.Textbox(
50
+ label="Anthropic API Key *",
51
+ type="password",
52
+ placeholder="sk-ant-...",
53
+ interactive=True
54
+ )
55
+ with gr.Row():
56
+ clear_btn = gr.ClearButton(
57
+ components=[question, ground_truth, file_name, file_link]
58
+ )
59
+ submit_btn = gr.Button("Submit", variant="primary")
60
+ with gr.Column(scale=1):
61
+ answer = gr.Textbox(
62
+ label="Answer",
63
+ interactive=False,
64
  lines=1,
65
  max_lines=3
66
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
+ submit_btn.click(
69
+ fn=ask,
70
+ inputs=[question, openai_api_key, gemini_api_key, anthropic_api_key, file_name],
71
+ outputs=answer
72
+ )
73
+
74
+ file_name.change(
75
+ fn=update_file_link,
76
+ inputs=[file_name],
77
+ outputs=[file_link]
78
+ )
79
+
80
+ with gr.Tabs(elem_classes=["full-width-tabs"]):
81
+ with gr.TabItem("GAIA Benchmark Level 1"):
82
+ gr.Examples(
83
+ examples=get_questions(QUESTION_FILE_PATH_GAIA, 1),
84
+ inputs=[question, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
85
+ examples_per_page=3,
86
+ cache_examples=False
87
+ )
88
 
89
+ with gr.TabItem("GAIA Benchmark Level 2"):
90
+ gr.Examples(
91
+ examples=get_questions(QUESTION_FILE_PATH_GAIA, 2),
92
+ inputs=[question, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
93
+ examples_per_page=3,
94
+ cache_examples=False
95
+ )
96
 
97
+ with gr.TabItem("GAIA Benchmark Level 3"):
98
+ gr.Examples(
99
+ examples=get_questions(QUESTION_FILE_PATH_GAIA, 3),
100
+ inputs=[question, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
101
+ examples_per_page=3,
102
+ cache_examples=False
103
+ )
104
 
105
+ with gr.TabItem("Humanity's Last Exam"):
106
+ gr.Examples(
107
+ examples=get_questions(QUESTION_FILE_PATH_HLE, 0),
108
+ inputs=[question, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
109
+ examples_per_page=3,
110
+ cache_examples=False
111
+ )
112
 
113
  gaia.launch(mcp_server=True, share=False, ssr_mode=False)