Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,7 @@ import os
|
|
| 14 |
from typing import List, Dict, Any, Optional
|
| 15 |
from smolagents import CodeAgent, Tool, tool, LiteLLMModel
|
| 16 |
from cool_agent import create_agent
|
|
|
|
| 17 |
|
| 18 |
import json
|
| 19 |
import re
|
|
@@ -81,6 +82,14 @@ class BasicAgent:
|
|
| 81 |
self.agent = agent_assets["agent"]
|
| 82 |
self.visual_inspection_tool = agent_assets["visualizer"]
|
| 83 |
self.document_inspection_tool = agent_assets["text_inspection_tool"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
def __call__(self, question: str, file_name: str = None) -> str:
|
| 86 |
"""
|
|
@@ -119,7 +128,7 @@ class BasicAgent:
|
|
| 119 |
try:
|
| 120 |
# Run the agent
|
| 121 |
response = self.agent.run(full_prompt)
|
| 122 |
-
|
| 123 |
# Clean up the response
|
| 124 |
# Remove any system-prompt-like text at the beginning
|
| 125 |
cleaned_response = re.sub(r'^.*?Answer:', '', response, flags=re.DOTALL).strip()
|
|
@@ -240,7 +249,13 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 240 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 241 |
continue
|
| 242 |
try:
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 245 |
results_log.append({"Task ID": task_id, "Question": question_text,
|
| 246 |
"Submitted Answer": submitted_answer})
|
|
|
|
| 14 |
from typing import List, Dict, Any, Optional
|
| 15 |
from smolagents import CodeAgent, Tool, tool, LiteLLMModel
|
| 16 |
from cool_agent import create_agent
|
| 17 |
+
from reformulator import prepare_response
|
| 18 |
|
| 19 |
import json
|
| 20 |
import re
|
|
|
|
| 82 |
self.agent = agent_assets["agent"]
|
| 83 |
self.visual_inspection_tool = agent_assets["visualizer"]
|
| 84 |
self.document_inspection_tool = agent_assets["text_inspection_tool"]
|
| 85 |
+
self.model = agent_assets["model"]
|
| 86 |
+
self.current_question = None
|
| 87 |
+
|
| 88 |
+
def assign_current_question(self, question: str):
|
| 89 |
+
self.current_question = question
|
| 90 |
+
|
| 91 |
+
def get_current_question(self):
|
| 92 |
+
return self.current_question
|
| 93 |
|
| 94 |
def __call__(self, question: str, file_name: str = None) -> str:
|
| 95 |
"""
|
|
|
|
| 128 |
try:
|
| 129 |
# Run the agent
|
| 130 |
response = self.agent.run(full_prompt)
|
| 131 |
+
self.assign_current_question(full_prompt)
|
| 132 |
# Clean up the response
|
| 133 |
# Remove any system-prompt-like text at the beginning
|
| 134 |
cleaned_response = re.sub(r'^.*?Answer:', '', response, flags=re.DOTALL).strip()
|
|
|
|
| 249 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 250 |
continue
|
| 251 |
try:
|
| 252 |
+
_ = agent(question_text, file_name)
|
| 253 |
+
agent_memory = agent.agent.write_memory_to_messages(summary_mode=True)
|
| 254 |
+
|
| 255 |
+
final_result = prepare_response(agent.get_current_question(), agent_memory,
|
| 256 |
+
reformulation_model=agent.model)
|
| 257 |
+
|
| 258 |
+
submitted_answer = str(final_result)
|
| 259 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 260 |
results_log.append({"Task ID": task_id, "Question": question_text,
|
| 261 |
"Submitted Answer": submitted_answer})
|