GT5557 commited on
Commit
53fedbd
·
verified ·
1 Parent(s): 4d214ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -29,7 +29,7 @@ sys.stdout.reconfigure(line_buffering=True)
29
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
30
 
31
  # Single values — no per-difficulty branching
32
- TIMEOUT_SECONDS = 120
33
  RECURSION_LIMIT = 12
34
  PAUSE_SECONDS = 1.0
35
 
@@ -105,9 +105,10 @@ def submit_answers(url: str, payload: dict) -> dict:
105
  return r.json()
106
 
107
 
108
- def fetch_task_file(task_id: str) -> tuple[str | None, str | None]:
109
  """
110
  Download the file attached to a task from GET /files/{task_id}.
 
111
  Returns (local_path, injected_text):
112
  - local_path: saved file path (for binary files like .py the model runs directly)
113
  - injected_text: pre-read text content to inject into the question (for Excel/CSV)
@@ -117,8 +118,18 @@ def fetch_task_file(task_id: str) -> tuple[str | None, str | None]:
117
  try:
118
  r = requests.get(url, timeout=20)
119
  if r.status_code == 404:
120
- log("File : no attachment (404)")
121
- return None, None
 
 
 
 
 
 
 
 
 
 
122
  r.raise_for_status()
123
 
124
  # Determine extension
@@ -139,10 +150,8 @@ def fetch_task_file(task_id: str) -> tuple[str | None, str | None]:
139
  ext = ".png"
140
  elif "jpeg" in ct or "jpg" in ct:
141
  ext = ".jpg"
142
- elif "python" in ct:
143
  ext = ".py"
144
- elif "text/plain" in ct:
145
- ext = ".txt"
146
  else:
147
  ext = ""
148
 
@@ -244,7 +253,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
244
  log("-" * 80)
245
 
246
  # Download any attached file and inject content into the question
247
- file_path, injected_text = fetch_task_file(task_id)
248
  if injected_text:
249
  # For Excel/CSV/text: embed the content directly so the model
250
  # doesn't need to re-download anything
 
29
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
30
 
31
  # Single values — no per-difficulty branching
32
+ TIMEOUT_SECONDS = 60
33
  RECURSION_LIMIT = 12
34
  PAUSE_SECONDS = 1.0
35
 
 
105
  return r.json()
106
 
107
 
108
+ def fetch_task_file(task_id: str, question: str = "") -> tuple[str | None, str | None]:
109
  """
110
  Download the file attached to a task from GET /files/{task_id}.
111
+ If that fails, search the question text for embedded file content or links.
112
  Returns (local_path, injected_text):
113
  - local_path: saved file path (for binary files like .py the model runs directly)
114
  - injected_text: pre-read text content to inject into the question (for Excel/CSV)
 
118
  try:
119
  r = requests.get(url, timeout=20)
120
  if r.status_code == 404:
121
+ log(f"File : endpoint /files/{task_id} returned 404 — trying alternate patterns")
122
+ # Fallback: try query param format
123
+ url2 = f"{DEFAULT_API_URL}/files?task_id={task_id}"
124
+ try:
125
+ r = requests.get(url2, timeout=20)
126
+ if r.status_code != 200:
127
+ log(f"File : no attachment found (both endpoints failed)")
128
+ return None, None
129
+ except Exception as e:
130
+ log(f"File : fallback endpoint also failed — {e}")
131
+ return None, None
132
+
133
  r.raise_for_status()
134
 
135
  # Determine extension
 
150
  ext = ".png"
151
  elif "jpeg" in ct or "jpg" in ct:
152
  ext = ".jpg"
153
+ elif "python" in ct or "text/plain" in ct:
154
  ext = ".py"
 
 
155
  else:
156
  ext = ""
157
 
 
253
  log("-" * 80)
254
 
255
  # Download any attached file and inject content into the question
256
+ file_path, injected_text = fetch_task_file(task_id, question)
257
  if injected_text:
258
  # For Excel/CSV/text: embed the content directly so the model
259
  # doesn't need to re-download anything