Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import inspect
|
|
@@ -44,16 +45,29 @@ class BasicAgent:
|
|
| 44 |
# deal with user problem
|
| 45 |
def handle_question(question):
|
| 46 |
try:
|
|
|
|
|
|
|
| 47 |
return process_question(question)
|
| 48 |
except Exception as e:
|
| 49 |
return f"Unexpected error: {str(e)}"
|
| 50 |
|
| 51 |
-
#
|
| 52 |
if __name__ == "__main__":
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 58 |
"""
|
| 59 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 1 |
import os
|
| 2 |
+
import time
|
| 3 |
import gradio as gr
|
| 4 |
import requests
|
| 5 |
import inspect
|
|
|
|
| 45 |
# deal with user problem
|
| 46 |
def handle_question(question):
|
| 47 |
try:
|
| 48 |
+
# 添加初始延迟避免突发请求
|
| 49 |
+
time.sleep(0.5)
|
| 50 |
return process_question(question)
|
| 51 |
except Exception as e:
|
| 52 |
return f"Unexpected error: {str(e)}"
|
| 53 |
|
| 54 |
+
# 测试调用
|
| 55 |
if __name__ == "__main__":
|
| 56 |
+
questions = [
|
| 57 |
+
"How many studio albums were published by Mercedes Sosa between 2000 and 2009?",
|
| 58 |
+
"What is the capital of France?",
|
| 59 |
+
"Calculate 15 multiplied by 27"
|
| 60 |
+
]
|
| 61 |
+
|
| 62 |
+
for q in questions:
|
| 63 |
+
print(f"Processing: {q}")
|
| 64 |
+
start = time.time()
|
| 65 |
+
response = handle_question(q)
|
| 66 |
+
elapsed = time.time() - start
|
| 67 |
+
print(f"Response ({elapsed:.2f}s): {response}")
|
| 68 |
+
print("-" * 50)
|
| 69 |
+
time.sleep(5)
|
| 70 |
+
|
| 71 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 72 |
"""
|
| 73 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|