Dkapsis commited on
Commit
5f2bd4a
·
1 Parent(s): a9182c5

use env variables as inputs

Browse files
.env.example DELETED
@@ -1,4 +0,0 @@
1
- SPACE_ID=
2
- HF_TOKEN=
3
- OPENAI_API_KEY=
4
- SERPAPI_API_KEY=
 
 
 
 
 
.gitignore DELETED
@@ -1 +0,0 @@
1
- .env
 
 
__pycache__/agents.cpython-310.pyc CHANGED
Binary files a/__pycache__/agents.cpython-310.pyc and b/__pycache__/agents.cpython-310.pyc differ
 
__pycache__/multi_agent.cpython-310.pyc CHANGED
Binary files a/__pycache__/multi_agent.cpython-310.pyc and b/__pycache__/multi_agent.cpython-310.pyc differ
 
__pycache__/prompts.cpython-310.pyc CHANGED
Binary files a/__pycache__/prompts.cpython-310.pyc and b/__pycache__/prompts.cpython-310.pyc differ
 
__pycache__/tools.cpython-310.pyc CHANGED
Binary files a/__pycache__/tools.cpython-310.pyc and b/__pycache__/tools.cpython-310.pyc differ
 
agents.py CHANGED
@@ -1,21 +1,39 @@
1
  from smolagents import OpenAIServerModel, CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, VisitWebpageTool
2
  import markdownify
 
3
 
4
  import tools
5
  import prompts
6
 
7
- MANAGER_MODEL = "deepseek-ai/DeepSeek-R1"
8
- AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
9
- FINAL_ANSWER_MODEL = "deepseek-ai/DeepSeek-R1" # OpenAIServerModel
10
- WEB_SEARCH_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
11
- IMAGE_ANALYSIS_MODEL = "HuggingFaceM4/idefics2-8b"
12
- AUDIO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
13
- VIDEO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
14
- YOUTUBE_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
15
- DOCUMENT_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
16
- ARITHMETIC_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
17
- CODE_GENERATION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
18
- CODE_EXECUTION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  # Agents
21
 
 
1
  from smolagents import OpenAIServerModel, CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, VisitWebpageTool
2
  import markdownify
3
+ import os
4
 
5
  import tools
6
  import prompts
7
 
8
+ if os.environ.get("OPENAI_API_KEY"):
9
+ MANAGER_MODEL = "deepseek-ai/DeepSeek-R1"
10
+ FINAL_ANSWER_MODEL = "deepseek-ai/DeepSeek-R1" # OpenAIServerModel
11
+ else:
12
+ MANAGER_MODEL = "deepseek-ai/DeepSeek-R1"
13
+ FINAL_ANSWER_MODEL = "deepseek-ai/DeepSeek-R1" # OpenAIServerModel
14
+
15
+ if os.environ.get("HF_TOKEN"):
16
+ AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
17
+ WEB_SEARCH_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
18
+ IMAGE_ANALYSIS_MODEL = "HuggingFaceM4/idefics2-8b"
19
+ AUDIO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
20
+ VIDEO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
21
+ YOUTUBE_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
22
+ DOCUMENT_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
23
+ ARITHMETIC_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
24
+ CODE_GENERATION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
25
+ CODE_EXECUTION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
26
+ else:
27
+ AGENT_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
28
+ WEB_SEARCH_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
29
+ IMAGE_ANALYSIS_MODEL = "HuggingFaceM4/idefics2-8b"
30
+ AUDIO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
31
+ VIDEO_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
32
+ YOUTUBE_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
33
+ DOCUMENT_ANALYSIS_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
34
+ ARITHMETIC_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
35
+ CODE_GENERATION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
36
+ CODE_EXECUTION_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
37
 
38
  # Agents
39
 
app.py CHANGED
@@ -145,12 +145,47 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
145
  results_df = pd.DataFrame(results_log)
146
  return status_message, results_df
147
 
148
- def test_init_agent_for_chat(text_input, history, file_name = ""):
 
 
 
 
 
 
 
 
149
 
150
  if file_name:
151
  file_name = f"data/{file_name}"
152
 
153
- submitted_answer = orchestrate(text_input, file_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  return submitted_answer
156
 
@@ -168,8 +203,83 @@ with gr.Blocks() as demo:
168
  """
169
  )
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  gr.LoginButton()
172
- gr.ChatInterface(test_init_agent_for_chat, type="messages")
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  # run_button = gr.Button("Run Evaluation & Submit All Answers")
175
 
@@ -183,32 +293,5 @@ with gr.Blocks() as demo:
183
  # )
184
 
185
  if __name__ == "__main__":
186
- load_dotenv()
187
- hf_token = os.getenv("HF_TOKEN")
188
- if hf_token:
189
- login(hf_token)
190
- else:
191
- print("ℹ️ HF_TOKEN environment variable not found (running locally?).")
192
-
193
- print("\n" + "-"*30 + " App Starting " + "-"*30)
194
- # Check for SPACE_HOST and SPACE_ID at startup for information
195
- space_host_startup = os.getenv("SPACE_HOST")
196
- space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
197
-
198
- if space_host_startup:
199
- print(f"✅ SPACE_HOST found: {space_host_startup}")
200
- print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
201
- else:
202
- print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
203
-
204
- if space_id_startup: # Print repo URLs if SPACE_ID is found
205
- print(f"✅ SPACE_ID found: {space_id_startup}")
206
- print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
207
- print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")
208
- else:
209
- print("ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined.")
210
-
211
- print("-"*(60 + len(" App Starting ")) + "\n")
212
-
213
  print("Launching Gradio Interface for Basic Agent Evaluation...")
214
  demo.launch(debug=True, share=False)
 
145
  results_df = pd.DataFrame(results_log)
146
  return status_message, results_df
147
 
148
+ def test_init_agent_for_chat(question,
149
+ openai_api_key,
150
+ gemini_api_key,
151
+ anthropic_api_key,
152
+ space_id,
153
+ hf_token,
154
+ serpapi_api_key,
155
+ file_name
156
+ ):
157
 
158
  if file_name:
159
  file_name = f"data/{file_name}"
160
 
161
+ if not question:
162
+ raise gr.Error("Question is required.")
163
+ if not openai_api_key:
164
+ raise gr.Error("OpenAi Key is required.")
165
+ if not space_id:
166
+ raise gr.Error("Space Id is required.")
167
+ if not hf_token:
168
+ raise gr.Error("HF Token is required.")
169
+
170
+ try:
171
+ os.environ["OPENAI_API_KEY"] = openai_api_key
172
+ os.environ["GEMINI_API_KEY"] = gemini_api_key
173
+ os.environ["ANTHROPIC_API_KEY"] = anthropic_api_key
174
+ os.environ["SPACE_ID"] = space_id
175
+ os.environ["HF_TOKEN"] = hf_token
176
+ os.environ["SERPAPI_API_KEY"] = serpapi_api_key
177
+
178
+ submitted_answer = orchestrate(question, file_name)
179
+
180
+ except Exception as e:
181
+ raise gr.Error(e)
182
+ finally:
183
+ del os.environ["OPENAI_API_KEY"]
184
+ del os.environ["GEMINI_API_KEY"]
185
+ del os.environ["ANTHROPIC_API_KEY"]
186
+ del os.environ["SPACE_ID"]
187
+ del os.environ["HF_TOKEN"]
188
+ del os.environ["OPENAI_API_KEY"]
189
 
190
  return submitted_answer
191
 
 
203
  """
204
  )
205
 
206
+ with gr.Row():
207
+ space_id = gr.Textbox(
208
+ label="space Id *",
209
+ type="password",
210
+ placeholder="sk‑...",
211
+ interactive=True
212
+ )
213
+ hf_token = gr.Textbox(
214
+ label="HF Token *",
215
+ type="password",
216
+ interactive=True
217
+ )
218
+ serpapi_api_key = gr.Textbox(
219
+ label="Serpapi API Key *",
220
+ type="password",
221
+ placeholder="sk-ant-...",
222
+ interactive=True
223
+ )
224
+
225
+ with gr.Row():
226
+ openai_api_key = gr.Textbox(
227
+ label="OpenAI API Key *",
228
+ type="password",
229
+ placeholder="sk‑...",
230
+ interactive=True
231
+ )
232
+ gemini_api_key = gr.Textbox(
233
+ label="Gemini API Key *",
234
+ type="password",
235
+ interactive=True
236
+ )
237
+ anthropic_api_key = gr.Textbox(
238
+ label="Anthropic API Key *",
239
+ type="password",
240
+ placeholder="sk-ant-...",
241
+ interactive=True
242
+ )
243
+
244
+ with gr.Row():
245
+ question = gr.Textbox(
246
+ label="Question *",
247
+ placeholder="In the 2025 Gradio Agents & MCP Hackathon, what percentage of participants submitted a solution during the last 24 hours?",
248
+ interactive=True
249
+ )
250
+
251
+ with gr.Row():
252
+ file_name = gr.Textbox(
253
+ label="File Name",
254
+ interactive=True,
255
+ scale=2
256
+ )
257
+
258
+ with gr.Row():
259
+ answer = gr.Textbox(
260
+ label="Answer",
261
+ lines=1,
262
+ interactive=False
263
+ )
264
+
265
+ with gr.Row():
266
+ submit_btn = gr.Button("Submit", variant="primary")
267
+
268
  gr.LoginButton()
269
+ submit_btn.click(
270
+ fn=test_init_agent_for_chat,
271
+ inputs=[question, openai_api_key, gemini_api_key, anthropic_api_key, space_id, hf_token, serpapi_api_key, file_name],
272
+ outputs=answer
273
+ )
274
+ # gr.ChatInterface(test_init_agent_for_chat(
275
+ # question = question,
276
+ # openai_api_key = openai_api_key,
277
+ # gemini_api_key = gemini_api_key,
278
+ # anthropic_api_key = anthropic_api_key,
279
+ # space_id = space_id,
280
+ # hf_token = hf_token,
281
+ # serpapi_api_key = serpapi_api_key
282
+ # ), type="messages")
283
 
284
  # run_button = gr.Button("Run Evaluation & Submit All Answers")
285
 
 
293
  # )
294
 
295
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  print("Launching Gradio Interface for Basic Agent Evaluation...")
297
  demo.launch(debug=True, share=False)
multi_agent.py CHANGED
@@ -15,15 +15,4 @@ def orchestrate(message, file_path):
15
 
16
  final_answer = agents.create_final_answer_agent(message).run(prompts.get_final_answer_prompt(message, initial_answer))
17
 
18
- return final_answer
19
- # def run_manager_workflow(message, file_path=None):
20
- # final_prompt = prompts.get_manager_prompt(message, file_path)
21
- # initial_answer = agents.create_simple_web_search_agent(message).run(message)
22
-
23
- # final_answer = agents.create_final_answer_agent(message).run(prompts.get_final_answer_prompt(message, initial_answer))
24
-
25
- # return final_answer
26
-
27
- # final_answer = run_manager_workflow(message)
28
-
29
- # return final_answer
 
15
 
16
  final_answer = agents.create_final_answer_agent(message).run(prompts.get_final_answer_prompt(message, initial_answer))
17
 
18
+ return final_answer