Spaces:
Running
Running
Commit ·
b1e2218
1
Parent(s): 04f8810
Fix upload endpoint: accept JSON payload, add logging
Browse filesTake token + paths as JSON string instead of gr.File.
Add print logging for upload flow debugging.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -241,22 +241,30 @@ def build_app() -> gr.Blocks:
|
|
| 241 |
ask_btn = gr.Button(visible=False)
|
| 242 |
ask_btn.click(api_ask_stream, inputs=ask_inputs, outputs=ask_output, api_name="ask")
|
| 243 |
|
| 244 |
-
# Upload endpoint — accepts
|
| 245 |
-
|
| 246 |
-
upload_files = gr.File(visible=False, file_count="multiple")
|
| 247 |
upload_output = gr.Textbox(visible=False)
|
| 248 |
|
| 249 |
-
def api_upload(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
if ACCESS_TOKEN and token != ACCESS_TOKEN:
|
| 251 |
return json.dumps({"error": "Invalid access token."})
|
| 252 |
-
if not
|
| 253 |
return json.dumps({"error": "No files provided."})
|
| 254 |
-
file_paths = [f.name if hasattr(f, "name") else str(f) for f in files]
|
| 255 |
workspace = save_uploaded_files(file_paths)
|
|
|
|
| 256 |
return json.dumps({"workspace_path": str(workspace), "file_count": len(file_paths)})
|
| 257 |
|
| 258 |
upload_btn = gr.Button(visible=False)
|
| 259 |
-
upload_btn.click(api_upload, inputs=
|
| 260 |
|
| 261 |
# Document viewer endpoint
|
| 262 |
doc_input = gr.Textbox(visible=False)
|
|
|
|
| 241 |
ask_btn = gr.Button(visible=False)
|
| 242 |
ask_btn.click(api_ask_stream, inputs=ask_inputs, outputs=ask_output, api_name="ask")
|
| 243 |
|
| 244 |
+
# Upload endpoint — accepts token + JSON list of file paths from /gradio_api/upload
|
| 245 |
+
upload_input = gr.Textbox(visible=False)
|
|
|
|
| 246 |
upload_output = gr.Textbox(visible=False)
|
| 247 |
|
| 248 |
+
def api_upload(payload):
|
| 249 |
+
print(f"[upload] raw payload: {payload!r}")
|
| 250 |
+
try:
|
| 251 |
+
data = json.loads(payload)
|
| 252 |
+
token = data.get("token", "")
|
| 253 |
+
file_paths = data.get("paths", [])
|
| 254 |
+
except (json.JSONDecodeError, AttributeError) as exc:
|
| 255 |
+
print(f"[upload] parse error: {exc}")
|
| 256 |
+
return json.dumps({"error": "Invalid payload."})
|
| 257 |
+
print(f"[upload] token={'***' if token else 'empty'}, paths={file_paths}")
|
| 258 |
if ACCESS_TOKEN and token != ACCESS_TOKEN:
|
| 259 |
return json.dumps({"error": "Invalid access token."})
|
| 260 |
+
if not file_paths:
|
| 261 |
return json.dumps({"error": "No files provided."})
|
|
|
|
| 262 |
workspace = save_uploaded_files(file_paths)
|
| 263 |
+
print(f"[upload] workspace created: {workspace}")
|
| 264 |
return json.dumps({"workspace_path": str(workspace), "file_count": len(file_paths)})
|
| 265 |
|
| 266 |
upload_btn = gr.Button(visible=False)
|
| 267 |
+
upload_btn.click(api_upload, inputs=upload_input, outputs=upload_output, api_name="upload")
|
| 268 |
|
| 269 |
# Document viewer endpoint
|
| 270 |
doc_input = gr.Textbox(visible=False)
|