lethaq commited on
Commit
70da919
·
verified ·
1 Parent(s): 42ebfbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -22
app.py CHANGED
@@ -1,4 +1,18 @@
1
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import gradio as gr
3
  import requests
4
  import inspect
@@ -196,21 +210,14 @@ class CodeAgent:
196
  print(f"Final answer: {answer[:100]}...")
197
  return answer
198
 
199
- def run_and_submit_all(profile: gr.OAuthProfile | None):
 
200
  """
201
  Fetches all questions, runs the Agent on them, submits all answers,
202
  and displays the results.
203
  """
204
  # --- Determine HF Space Runtime URL and Repo URL ---
205
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
206
-
207
- if profile:
208
- username= f"{profile.username}"
209
- print(f"User logged in: {username}")
210
- else:
211
- print("User not logged in.")
212
- return "Please Login to Hugging Face with the button.", None
213
-
214
  api_url = DEFAULT_API_URL
215
  questions_url = f"{api_url}/questions"
216
  submit_url = f"{api_url}/submit"
@@ -328,8 +335,7 @@ with gr.Blocks() as demo:
328
  """
329
  **Instructions:**
330
  1. Make sure you have set the GEMINI_API_KEY environment variable in your Space settings.
331
- 2. Log in to your Hugging Face account using the button below.
332
- 3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run the agent, and submit answers.
333
 
334
  This agent uses:
335
  - Gemini 2.0 Flash Lite model for reasoning
@@ -337,8 +343,6 @@ with gr.Blocks() as demo:
337
  """
338
  )
339
 
340
- gr.LoginButton()
341
-
342
  run_button = gr.Button("Run Evaluation & Submit All Answers")
343
 
344
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
@@ -366,20 +370,18 @@ with gr.Blocks() as demo:
366
  except Exception as e:
367
  return f"Error: {str(e)}"
368
 
 
369
  run_button.click(
370
- fn=run_and_submit_all,
371
- inputs=gr.OAuthProfile(),
372
- outputs=[status_output, results_table]
373
  )
374
-
375
 
376
- run_button.click(
377
- fn=run_and_submit_all,
378
- inputs=login_button,
379
- outputs=[status_output, results_table]
380
  )
381
 
382
-
383
  if __name__ == "__main__":
384
  print("\n" + "-"*30 + " App Starting " + "-"*30)
385
  # Check for SPACE_HOST and SPACE_ID at startup for information
@@ -405,3 +407,4 @@ if __name__ == "__main__":
405
  demo.launch(debug=True, share=False)
406
 
407
 
 
 
1
  import os
2
+ import sys
3
+ import subprocess
4
+
5
+ # 检查并安装缺失的依赖
6
+ required_packages = ["litellm", "duckduckgo-search"]
7
+ for package in required_packages:
8
+ try:
9
+ __import__(package)
10
+ except ImportError:
11
+ print(f"Installing {package}...")
12
+ subprocess.check_call([sys.executable, "-m", "pip", "install", package])
13
+ print(f"{package} installed successfully!")
14
+
15
+ # 现在导入所需模块
16
  import gradio as gr
17
  import requests
18
  import inspect
 
210
  print(f"Final answer: {answer[:100]}...")
211
  return answer
212
 
213
+ # 简化版本,不使用OAuthProfile
214
+ def run_and_submit_all():
215
  """
216
  Fetches all questions, runs the Agent on them, submits all answers,
217
  and displays the results.
218
  """
219
  # --- Determine HF Space Runtime URL and Repo URL ---
220
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
 
 
 
 
 
 
 
 
221
  api_url = DEFAULT_API_URL
222
  questions_url = f"{api_url}/questions"
223
  submit_url = f"{api_url}/submit"
 
335
  """
336
  **Instructions:**
337
  1. Make sure you have set the GEMINI_API_KEY environment variable in your Space settings.
338
+ 2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run the agent, and submit answers.
 
339
 
340
  This agent uses:
341
  - Gemini 2.0 Flash Lite model for reasoning
 
343
  """
344
  )
345
 
 
 
346
  run_button = gr.Button("Run Evaluation & Submit All Answers")
347
 
348
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
 
370
  except Exception as e:
371
  return f"Error: {str(e)}"
372
 
373
+ # 完全移除OAuthProfile相关代码
374
  run_button.click(
375
+ fn=run_and_submit_all,
376
+ outputs=[status_output, results_table]
 
377
  )
 
378
 
379
+ test_btn.click(
380
+ fn=test_single_question,
381
+ inputs=[question_in],
382
+ outputs=[answer_out]
383
  )
384
 
 
385
  if __name__ == "__main__":
386
  print("\n" + "-"*30 + " App Starting " + "-"*30)
387
  # Check for SPACE_HOST and SPACE_ID at startup for information
 
407
  demo.launch(debug=True, share=False)
408
 
409
 
410
+