Update app.py
Browse files
app.py
CHANGED
|
@@ -74,7 +74,6 @@ class BasicAgent:
|
|
| 74 |
inputs = self.tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)
|
| 75 |
outputs = self.model.generate(**inputs, max_new_tokens=100)
|
| 76 |
answer = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 77 |
-
# Extract concise answer
|
| 78 |
answer = answer.strip().split("\n")[0].strip()
|
| 79 |
print(f"Reasoning: Qwen returned answer: {answer}")
|
| 80 |
return answer
|
|
@@ -89,7 +88,7 @@ class BasicAgent:
|
|
| 89 |
response.raise_for_status()
|
| 90 |
soup = self.BeautifulSoup(response.text, 'html.parser')
|
| 91 |
context = soup.find("div", id="content").text if soup.find("div", id="content") else response.text
|
| 92 |
-
context = context[:4000]
|
| 93 |
print(f"Reasoning: Web context fetched (first 100 chars): {context[:100]}...")
|
| 94 |
prompt = f"Answer the following question based on the context:\nQuestion: {question}\nContext: {context}\nProvide only the final answer in the exact format required (e.g., number, comma-separated list, or name)."
|
| 95 |
return self.query_qwen(prompt, question)
|
|
@@ -124,7 +123,7 @@ class BasicAgent:
|
|
| 124 |
print("Reasoning: Transcriber unavailable.")
|
| 125 |
return "Transcriber unavailable"
|
| 126 |
except Exception as e:
|
| 127 |
-
print(f"Reasoning: Error processing audio: {e")
|
| 128 |
return "Unable to process audio"
|
| 129 |
|
| 130 |
def process_chess_image(self, image_path, question):
|
|
@@ -133,7 +132,6 @@ class BasicAgent:
|
|
| 133 |
print(f"Reasoning: Chess image not found: {image_path}")
|
| 134 |
return "Image not found"
|
| 135 |
try:
|
| 136 |
-
# Placeholder FEN (requires vision model for actual conversion)
|
| 137 |
fen = "rnbqkbnr/pppp1ppp/5n2/4p3/4P3/5N2/PPPP1PPP/RNBQKBNR w KQkq - 0 1"
|
| 138 |
print(f"Reasoning: Using placeholder FEN: {fen}")
|
| 139 |
if self.stockfish:
|
|
@@ -164,13 +162,12 @@ class BasicAgent:
|
|
| 164 |
def process_table(self, table_text, question):
|
| 165 |
print(f"Reasoning: Processing table data (first 100 chars): {table_text[:100]}...")
|
| 166 |
try:
|
| 167 |
-
lines = table_text.split("\n")[1:]
|
| 168 |
table_data = []
|
| 169 |
for line in lines:
|
| 170 |
if line.strip():
|
| 171 |
row = line.strip("|").split("|")[1:]
|
| 172 |
table_data.append(row)
|
| 173 |
-
# Assume 5x5 table (common in GAIA)
|
| 174 |
df = self.pd.DataFrame(table_data, index=['a', 'b', 'c', 'd', 'e'], columns=['a', 'b', 'c', 'd', 'e'])
|
| 175 |
print(f"Reasoning: Table parsed:\n{df.to_string()}")
|
| 176 |
prompt = f"Analyze the following table to answer the question:\nQuestion: {question}\nTable:\n{df.to_string()}\nProvide only the final answer in the exact format required (e.g., comma-separated list)."
|
|
@@ -199,7 +196,6 @@ class BasicAgent:
|
|
| 199 |
print(f"Full Question: {question}")
|
| 200 |
question_lower = question.lower()
|
| 201 |
|
| 202 |
-
# Classify question and select tool
|
| 203 |
if ".mp3" in question_lower:
|
| 204 |
print("Reasoning: Detected audio question.")
|
| 205 |
file_name = self.re.search(r'[\w\s]+\.mp3', question, self.re.IGNORECASE)
|
|
|
|
| 74 |
inputs = self.tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)
|
| 75 |
outputs = self.model.generate(**inputs, max_new_tokens=100)
|
| 76 |
answer = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 77 |
answer = answer.strip().split("\n")[0].strip()
|
| 78 |
print(f"Reasoning: Qwen returned answer: {answer}")
|
| 79 |
return answer
|
|
|
|
| 88 |
response.raise_for_status()
|
| 89 |
soup = self.BeautifulSoup(response.text, 'html.parser')
|
| 90 |
context = soup.find("div", id="content").text if soup.find("div", id="content") else response.text
|
| 91 |
+
context = context[:4000]
|
| 92 |
print(f"Reasoning: Web context fetched (first 100 chars): {context[:100]}...")
|
| 93 |
prompt = f"Answer the following question based on the context:\nQuestion: {question}\nContext: {context}\nProvide only the final answer in the exact format required (e.g., number, comma-separated list, or name)."
|
| 94 |
return self.query_qwen(prompt, question)
|
|
|
|
| 123 |
print("Reasoning: Transcriber unavailable.")
|
| 124 |
return "Transcriber unavailable"
|
| 125 |
except Exception as e:
|
| 126 |
+
print(f"Reasoning: Error processing audio: {e}")
|
| 127 |
return "Unable to process audio"
|
| 128 |
|
| 129 |
def process_chess_image(self, image_path, question):
|
|
|
|
| 132 |
print(f"Reasoning: Chess image not found: {image_path}")
|
| 133 |
return "Image not found"
|
| 134 |
try:
|
|
|
|
| 135 |
fen = "rnbqkbnr/pppp1ppp/5n2/4p3/4P3/5N2/PPPP1PPP/RNBQKBNR w KQkq - 0 1"
|
| 136 |
print(f"Reasoning: Using placeholder FEN: {fen}")
|
| 137 |
if self.stockfish:
|
|
|
|
| 162 |
def process_table(self, table_text, question):
|
| 163 |
print(f"Reasoning: Processing table data (first 100 chars): {table_text[:100]}...")
|
| 164 |
try:
|
| 165 |
+
lines = table_text.split("\n")[1:]
|
| 166 |
table_data = []
|
| 167 |
for line in lines:
|
| 168 |
if line.strip():
|
| 169 |
row = line.strip("|").split("|")[1:]
|
| 170 |
table_data.append(row)
|
|
|
|
| 171 |
df = self.pd.DataFrame(table_data, index=['a', 'b', 'c', 'd', 'e'], columns=['a', 'b', 'c', 'd', 'e'])
|
| 172 |
print(f"Reasoning: Table parsed:\n{df.to_string()}")
|
| 173 |
prompt = f"Analyze the following table to answer the question:\nQuestion: {question}\nTable:\n{df.to_string()}\nProvide only the final answer in the exact format required (e.g., comma-separated list)."
|
|
|
|
| 196 |
print(f"Full Question: {question}")
|
| 197 |
question_lower = question.lower()
|
| 198 |
|
|
|
|
| 199 |
if ".mp3" in question_lower:
|
| 200 |
print("Reasoning: Detected audio question.")
|
| 201 |
file_name = self.re.search(r'[\w\s]+\.mp3', question, self.re.IGNORECASE)
|