naman1102 commited on
Commit
7ea58f4
·
1 Parent(s): 2c6be25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -254,7 +254,10 @@ class BasicAgent:
254
  data = response.content
255
  print(f"Successfully downloaded file, size: {len(data)} bytes")
256
 
257
- kind = mimetypes.guess_type(state["file_url"])[0] or ""
 
 
 
258
  print(f"Detected file type: {kind}")
259
 
260
  if "image" in kind:
@@ -379,11 +382,13 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
379
  try:
380
  print(f"\nProcessing question {task_id}...")
381
 
382
- # Handle file URL with fallback to generic attachment endpoint
383
  raw_url = item.get("file_url") or ""
384
- if not raw_url: # fallback for empty field
385
  raw_url = f"/files/{task_id}" # generic attachment endpoint
386
- file_url = f"{api_url}{raw_url}" # absolute URL
 
 
387
 
388
  answer = agent(
389
  question=item.get("question", ""),
 
254
  data = response.content
255
  print(f"Successfully downloaded file, size: {len(data)} bytes")
256
 
257
+ # Get content type from response headers first, fallback to URL-based detection
258
+ kind = response.headers.get("Content-Type", "")
259
+ if not kind: # fallback if header missing
260
+ kind = mimetypes.guess_type(state["file_url"])[0] or ""
261
  print(f"Detected file type: {kind}")
262
 
263
  if "image" in kind:
 
382
  try:
383
  print(f"\nProcessing question {task_id}...")
384
 
385
+ # Handle file URL with conditional fallback to generic attachment endpoint
386
  raw_url = item.get("file_url") or ""
387
+ if not raw_url and "attached" in item["question"].lower():
388
  raw_url = f"/files/{task_id}" # generic attachment endpoint
389
+
390
+ # Only construct file_url if we have a raw_url
391
+ file_url = f"{api_url}{raw_url}" if raw_url else "" # empty means "no file"
392
 
393
  answer = agent(
394
  question=item.get("question", ""),