Update app.py
Browse files
app.py
CHANGED
@@ -247,22 +247,18 @@ class BasicAgent:
|
|
247 |
def _generate_answer(self, state: AgentState) -> AgentState:
|
248 |
if state["file_url"]:
|
249 |
try:
|
250 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
kind = mimetypes.guess_type(state["file_url"])[0] or ""
|
252 |
print(f"Detected file type: {kind}")
|
253 |
|
254 |
-
# Download file with timeout and error handling
|
255 |
-
try:
|
256 |
-
response = requests.get(state["file_url"], timeout=30)
|
257 |
-
response.raise_for_status()
|
258 |
-
data = response.content
|
259 |
-
print(f"Successfully downloaded file, size: {len(data)} bytes")
|
260 |
-
except requests.exceptions.RequestException as e:
|
261 |
-
print(f"Error downloading file: {e}")
|
262 |
-
state["final_answer"] = f"Error downloading file: {str(e)}"
|
263 |
-
state["current_step"] = "done"
|
264 |
-
return state
|
265 |
-
|
266 |
if "image" in kind:
|
267 |
print("Processing as image...")
|
268 |
answer = image_qa_bytes(data, state["question"])
|
@@ -283,6 +279,11 @@ class BasicAgent:
|
|
283 |
state["final_answer"] = answer
|
284 |
state["current_step"] = "done"
|
285 |
return state
|
|
|
|
|
|
|
|
|
|
|
286 |
except Exception as e:
|
287 |
print(f"\nError processing file {state['file_url']}: {str(e)}")
|
288 |
state["final_answer"] = f"Error processing file: {str(e)}"
|
|
|
247 |
def _generate_answer(self, state: AgentState) -> AgentState:
|
248 |
if state["file_url"]:
|
249 |
try:
|
250 |
+
print(f"Downloading {state['file_url']} …")
|
251 |
+
headers = {}
|
252 |
+
if HF_TOKEN:
|
253 |
+
headers["Authorization"] = f"Bearer {HF_TOKEN}"
|
254 |
+
response = requests.get(state["file_url"], headers=headers, timeout=30)
|
255 |
+
response.raise_for_status()
|
256 |
+
data = response.content
|
257 |
+
print(f"Successfully downloaded file, size: {len(data)} bytes")
|
258 |
+
|
259 |
kind = mimetypes.guess_type(state["file_url"])[0] or ""
|
260 |
print(f"Detected file type: {kind}")
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
if "image" in kind:
|
263 |
print("Processing as image...")
|
264 |
answer = image_qa_bytes(data, state["question"])
|
|
|
279 |
state["final_answer"] = answer
|
280 |
state["current_step"] = "done"
|
281 |
return state
|
282 |
+
except requests.exceptions.RequestException as e:
|
283 |
+
print(f"Error downloading file: {e}")
|
284 |
+
state["final_answer"] = f"Error downloading file: {str(e)}"
|
285 |
+
state["current_step"] = "done"
|
286 |
+
return state
|
287 |
except Exception as e:
|
288 |
print(f"\nError processing file {state['file_url']}: {str(e)}")
|
289 |
state["final_answer"] = f"Error processing file: {str(e)}"
|