Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -50,17 +50,37 @@ class BasicAgent:
|
|
50 |
# Ensure result is always a string
|
51 |
if not isinstance(result, str):
|
52 |
result = str(result)
|
|
|
|
|
|
|
|
|
|
|
53 |
return result
|
54 |
except Exception as e:
|
55 |
print(traceback.format_exc())
|
56 |
error_msg = f"Error running agent: {str(e)}"
|
57 |
return f"I encountered an issue while processing your question: {str(e)}"
|
58 |
|
|
|
|
|
|
|
|
|
|
|
59 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
60 |
"""
|
61 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
62 |
and displays the results.
|
63 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
65 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
66 |
|
@@ -149,6 +169,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
149 |
f"Message: {result_data.get('message', 'No message received.')}"
|
150 |
)
|
151 |
# print("Submission successful.")
|
|
|
152 |
results_df = pd.DataFrame(results_log)
|
153 |
return final_status, results_df
|
154 |
except requests.exceptions.HTTPError as e:
|
|
|
50 |
# Ensure result is always a string
|
51 |
if not isinstance(result, str):
|
52 |
result = str(result)
|
53 |
+
# 提取最终答案 - 如果结果包含"Final answer:"格式
|
54 |
+
if "Final answer:" in result:
|
55 |
+
# 只提取最终答案部分
|
56 |
+
final_answer_part = result.split("Final answer:")[1].strip()
|
57 |
+
return final_answer_part
|
58 |
return result
|
59 |
except Exception as e:
|
60 |
print(traceback.format_exc())
|
61 |
error_msg = f"Error running agent: {str(e)}"
|
62 |
return f"I encountered an issue while processing your question: {str(e)}"
|
63 |
|
64 |
+
|
65 |
+
|
66 |
+
# 添加全局变量来存储已经处理过的问题和答案
|
67 |
+
processed_questions = {}
|
68 |
+
submission_completed = False
|
69 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
70 |
"""
|
71 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
72 |
and displays the results.
|
73 |
"""
|
74 |
+
|
75 |
+
global processed_questions, submission_completed
|
76 |
+
|
77 |
+
# 如果已经完成提交,直接返回之前的结果
|
78 |
+
if submission_completed and processed_questions:
|
79 |
+
results_log = []
|
80 |
+
for task_id, data in processed_questions.items():
|
81 |
+
results_log.append({"Task ID": task_id, "Question": data["question"], "Submitted Answer": data["answer"]})
|
82 |
+
return "已经完成提交,请刷新页面重新开始。", pd.DataFrame(results_log)
|
83 |
+
|
84 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
85 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
86 |
|
|
|
169 |
f"Message: {result_data.get('message', 'No message received.')}"
|
170 |
)
|
171 |
# print("Submission successful.")
|
172 |
+
submission_completed = True
|
173 |
results_df = pd.DataFrame(results_log)
|
174 |
return final_status, results_df
|
175 |
except requests.exceptions.HTTPError as e:
|