Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -3
src/streamlit_app.py
CHANGED
|
@@ -92,7 +92,6 @@ st.set_page_config(
|
|
| 92 |
# Backend API URL (your HF backend)
|
| 93 |
API_BASE_URL = os.environ.get("API_BASE_URL", "https://hamza4100-multi-pdf-rag-api.hf.space")
|
| 94 |
|
| 95 |
-
|
| 96 |
# Pre-configured API keys that match backend.
|
| 97 |
# Read from env `API_KEYS` (comma-separated). This defines the limited pool of keys.
|
| 98 |
raw_keys = os.environ.get("API_KEYS", "")
|
|
@@ -236,8 +235,17 @@ def upload_pdf(api_key: str, file) -> Dict:
|
|
| 236 |
files=files,
|
| 237 |
timeout=(10, read_timeout)
|
| 238 |
)
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
except requests.exceptions.ReadTimeout as e:
|
| 242 |
# Retry once for transient slow responses
|
| 243 |
if attempt < max_retries:
|
|
|
|
| 92 |
# Backend API URL (your HF backend)
|
| 93 |
API_BASE_URL = os.environ.get("API_BASE_URL", "https://hamza4100-multi-pdf-rag-api.hf.space")
|
| 94 |
|
|
|
|
| 95 |
# Pre-configured API keys that match backend.
|
| 96 |
# Read from env `API_KEYS` (comma-separated). This defines the limited pool of keys.
|
| 97 |
raw_keys = os.environ.get("API_KEYS", "")
|
|
|
|
| 235 |
files=files,
|
| 236 |
timeout=(10, read_timeout)
|
| 237 |
)
|
| 238 |
+
try:
|
| 239 |
+
response.raise_for_status()
|
| 240 |
+
return {"success": True, "data": response.json()}
|
| 241 |
+
except requests.exceptions.HTTPError as http_err:
|
| 242 |
+
# Include status code and server response body for easier debugging
|
| 243 |
+
text = None
|
| 244 |
+
try:
|
| 245 |
+
text = response.text
|
| 246 |
+
except Exception:
|
| 247 |
+
text = str(http_err)
|
| 248 |
+
return {"success": False, "error": f"HTTP {response.status_code}: {text}"}
|
| 249 |
except requests.exceptions.ReadTimeout as e:
|
| 250 |
# Retry once for transient slow responses
|
| 251 |
if attempt < max_retries:
|