files
Browse files
app.py
CHANGED
@@ -224,6 +224,32 @@ class BasicAgent:
|
|
224 |
return raw.split(':', 1)[-1].strip()
|
225 |
|
226 |
def _generate_answer(self, state: AgentState) -> AgentState:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
prompt = f"""
|
228 |
Answer this question using the materials provided.
|
229 |
|
|
|
224 |
return raw.split(':', 1)[-1].strip()
|
225 |
|
226 |
def _generate_answer(self, state: AgentState) -> AgentState:
|
227 |
+
if state["file_url"]:
|
228 |
+
try:
|
229 |
+
kind = mimetypes.guess_type(state["file_url"])[0] or ""
|
230 |
+
data = requests.get(state["file_url"]).content
|
231 |
+
|
232 |
+
if "image" in kind:
|
233 |
+
answer = image_qa_bytes(data, state["question"])
|
234 |
+
elif "video" in kind:
|
235 |
+
answer = video_label_bytes(data)
|
236 |
+
elif kind.endswith("spreadsheet") or state["file_url"].endswith((".xlsx", ".csv")):
|
237 |
+
answer = sheet_answer_bytes(data, state["question"])
|
238 |
+
elif state["file_url"].endswith(".py"):
|
239 |
+
answer = run_python(data.decode())
|
240 |
+
else:
|
241 |
+
answer = "Unsupported file type"
|
242 |
+
|
243 |
+
state["final_answer"] = answer
|
244 |
+
state["current_step"] = "done"
|
245 |
+
return state
|
246 |
+
except Exception as e:
|
247 |
+
print(f"\nError processing file {state['file_url']}: {str(e)}")
|
248 |
+
state["final_answer"] = f"Error processing file: {str(e)}"
|
249 |
+
state["current_step"] = "done"
|
250 |
+
return state
|
251 |
+
|
252 |
+
# For text-only questions, use the LLM
|
253 |
prompt = f"""
|
254 |
Answer this question using the materials provided.
|
255 |
|