laverdes commited on
Commit
bf10b54
·
verified ·
1 Parent(s): 769a765

fix: saving file binary to tmp/

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -138,27 +138,34 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
138
  question_level = item.get("Level")
139
  question_file_name = item.get("file_name", None)
140
  print("\nquestion level: ", question_level)
 
141
  print("question file_name: ", question_file_name)
142
 
143
  if question_file_name:
144
  file_url = files_url.format(api_url, task_id)
145
- print("file_url: ", file_url )
146
  file_response = requests.get(file_url, timeout=15)
147
  file_response.raise_for_status()
148
- print("file_response: ", file_response.json())
 
 
 
 
 
 
149
 
150
  found= False
151
  metadata = {}
152
  for root, dirs, files in os.walk("/"):
153
  if question_file_name in files:
154
  file_path = os.path.join(root, question_file_name)
155
- print("FILE FOUND AT:", file_path)
156
  metadata = {'image_path': file_path} if '.png' in question_file_name else {}
157
  found=True
 
158
  if question_file_name and not found:
159
- print("FILE WAS NOT FOUND LOCALLY... try making an api request to .files/ or ./static in the hf.space target (or check it manually first)")
160
- import sys
161
- sys.exit()
162
 
163
  if not task_id or question_text is None:
164
  print(f"Skipping item with missing task_id or question: {item}")
 
138
  question_level = item.get("Level")
139
  question_file_name = item.get("file_name", None)
140
  print("\nquestion level: ", question_level)
141
+ print("task_id: ", task_id)
142
  print("question file_name: ", question_file_name)
143
 
144
  if question_file_name:
145
  file_url = files_url.format(api_url, task_id)
146
+ print("file_url: ", file_url)
147
  file_response = requests.get(file_url, timeout=15)
148
  file_response.raise_for_status()
149
+ print("file_response: ", file_response.content[0:50])
150
+ save_path = os.path.join("/tmp", question_file_name)
151
+ print("save_path: ", save_path)
152
+
153
+ with open(save_path, "wb") as f:
154
+ f.write(file_response.content)
155
+ print(f"✅ file saved to: {save_path}")
156
 
157
  found= False
158
  metadata = {}
159
  for root, dirs, files in os.walk("/"):
160
  if question_file_name in files:
161
  file_path = os.path.join(root, question_file_name)
162
+ print("file found at: ", file_path)
163
  metadata = {'image_path': file_path} if '.png' in question_file_name else {}
164
  found=True
165
+
166
  if question_file_name and not found:
167
+ print("FileNotFoundError: try making an api request to .files/ or ./static in the hf.space target (or check it manually first)")
168
+ break
 
169
 
170
  if not task_id or question_text is None:
171
  print(f"Skipping item with missing task_id or question: {item}")