Spaces:
Sleeping
Sleeping
Samuel Thomas
commited on
Commit
·
0616341
1
Parent(s):
a430e55
error checking
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
from tools import intelligent_agent, get_file_type, write_bytes_to_temp_dir, State
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
|
@@ -61,24 +62,29 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 61 |
return f"An unexpected error occurred fetching questions: {e}", None
|
| 62 |
|
| 63 |
# 2. Create states
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
# Call the API to retrieve the file; adjust params as needed
|
| 72 |
-
task_id = item['task_id']
|
| 73 |
-
api_response = requests.get(f"{api_url}/{task_id}")
|
| 74 |
-
if api_response.status_code == 200:
|
| 75 |
-
item['input_file'] = api_response.content # Store file as bytes
|
| 76 |
-
item['file_type'] = get_file_type(file_name)
|
| 77 |
-
item['file_path'] = write_bytes_to_temp_dir(item['input_file'], file_name)
|
| 78 |
else:
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
#
|
| 82 |
try:
|
| 83 |
ans = []
|
| 84 |
for r in range(len(hf_questions)):
|
|
@@ -92,8 +98,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 92 |
print('\n')
|
| 93 |
#ans.append(temp_ans)
|
| 94 |
except Exception as e:
|
| 95 |
-
|
| 96 |
-
|
|
|
|
| 97 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 98 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 99 |
print(agent_code)
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
import traceback
|
| 7 |
from tools import intelligent_agent, get_file_type, write_bytes_to_temp_dir, State
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
|
|
|
| 62 |
return f"An unexpected error occurred fetching questions: {e}", None
|
| 63 |
|
| 64 |
# 2. Create states
|
| 65 |
+
try:
|
| 66 |
+
for item in hf_questions:
|
| 67 |
+
file_name = item.get('file_name', '')
|
| 68 |
+
if file_name == '':
|
| 69 |
+
item['input_file'] = None
|
| 70 |
+
item['file_type'] = None
|
| 71 |
+
item['file_path'] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
else:
|
| 73 |
+
# Call the API to retrieve the file; adjust params as needed
|
| 74 |
+
task_id = item['task_id']
|
| 75 |
+
api_response = requests.get(f"{api_url}/{task_id}")
|
| 76 |
+
if api_response.status_code == 200:
|
| 77 |
+
item['input_file'] = api_response.content # Store file as bytes
|
| 78 |
+
item['file_type'] = get_file_type(file_name)
|
| 79 |
+
item['file_path'] = write_bytes_to_temp_dir(item['input_file'], file_name)
|
| 80 |
+
else:
|
| 81 |
+
item['input_file'] = None # Or handle error as needed
|
| 82 |
+
except Exception as e:
|
| 83 |
+
tb_str = traceback.format_exc()
|
| 84 |
+
print(f"Error creating new states: {tb_str}")
|
| 85 |
+
return f"Error creating new states: {tb_str}", None
|
| 86 |
|
| 87 |
+
# 3. Setup states for questions
|
| 88 |
try:
|
| 89 |
ans = []
|
| 90 |
for r in range(len(hf_questions)):
|
|
|
|
| 98 |
print('\n')
|
| 99 |
#ans.append(temp_ans)
|
| 100 |
except Exception as e:
|
| 101 |
+
tb_str = traceback.format_exc()
|
| 102 |
+
print(f"Error setting up states: {tb_str}")
|
| 103 |
+
return f"Error setting up states: {tb_str}", None
|
| 104 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 105 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 106 |
print(agent_code)
|