Spaces:
Sleeping
Sleeping
Upload public_routes.py
Browse files
backend/media_analysis/public_routes.py
CHANGED
|
@@ -31,6 +31,9 @@ def media_analyze_public():
|
|
| 31 |
return jsonify({"error": "JSON object required"}), 400
|
| 32 |
question = body.get("question")
|
| 33 |
idx = body.get("metadata_row_index")
|
|
|
|
|
|
|
|
|
|
| 34 |
if not isinstance(question, str) or not (1 <= len(question.strip()) <= 1200):
|
| 35 |
return jsonify({"error": "question must be 1-1200 characters"}), 400
|
| 36 |
if isinstance(idx, bool) or not isinstance(idx, int) or idx < 0:
|
|
@@ -74,10 +77,12 @@ def media_analyze_public():
|
|
| 74 |
return jsonify({"error": "Media analysis is busy; please retry shortly"}), 429
|
| 75 |
try:
|
| 76 |
result = analyze_media_question(question.strip(), [paper], enabled=True,
|
| 77 |
-
provider=provider, model=model, max_output_tokens=4096,
|
| 78 |
-
evidence_mode="combined", export_csv=
|
|
|
|
| 79 |
# Do not send large duplicate tabular records: CSV already carries the data.
|
| 80 |
result.pop("structured_data", None)
|
|
|
|
| 81 |
return jsonify(result)
|
| 82 |
except (MediaSelectionError, VisionConfigurationError, ValueError, FileNotFoundError) as exc:
|
| 83 |
return jsonify({"error": str(exc)}), 400
|
|
|
|
| 31 |
return jsonify({"error": "JSON object required"}), 400
|
| 32 |
question = body.get("question")
|
| 33 |
idx = body.get("metadata_row_index")
|
| 34 |
+
export_csv = body.get("export_csv", True) # legacy clients remain CSV-first
|
| 35 |
+
if not isinstance(export_csv, bool):
|
| 36 |
+
return jsonify({"error": "export_csv must be a boolean"}), 400
|
| 37 |
if not isinstance(question, str) or not (1 <= len(question.strip()) <= 1200):
|
| 38 |
return jsonify({"error": "question must be 1-1200 characters"}), 400
|
| 39 |
if isinstance(idx, bool) or not isinstance(idx, int) or idx < 0:
|
|
|
|
| 77 |
return jsonify({"error": "Media analysis is busy; please retry shortly"}), 429
|
| 78 |
try:
|
| 79 |
result = analyze_media_question(question.strip(), [paper], enabled=True,
|
| 80 |
+
provider=provider, model=model, max_output_tokens=4096 if export_csv else 1600,
|
| 81 |
+
evidence_mode="combined", export_csv=export_csv,
|
| 82 |
+
analysis_mode="extract_all" if export_csv else "interpret")
|
| 83 |
# Do not send large duplicate tabular records: CSV already carries the data.
|
| 84 |
result.pop("structured_data", None)
|
| 85 |
+
result["export_csv_requested"] = export_csv
|
| 86 |
return jsonify(result)
|
| 87 |
except (MediaSelectionError, VisionConfigurationError, ValueError, FileNotFoundError) as exc:
|
| 88 |
return jsonify({"error": str(exc)}), 400
|