Spaces:
Sleeping
Sleeping
Commit ·
ad40a54
1
Parent(s): 41146f6
Changing streamlit warning in Backend optional;
Browse files- api_server.py +36 -9
api_server.py
CHANGED
|
@@ -279,17 +279,44 @@ def serialize_for_api(results: Dict) -> Dict:
|
|
| 279 |
return serialized
|
| 280 |
|
| 281 |
def run_streamlit():
|
| 282 |
-
"""Run Streamlit in a separate thread"""
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
if __name__ == "__main__":
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
# Start FastAPI
|
|
|
|
| 295 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 279 |
return serialized
|
| 280 |
|
| 281 |
def run_streamlit():
|
| 282 |
+
"""Run Streamlit in a separate thread (optional - only if app file exists)"""
|
| 283 |
+
import logging
|
| 284 |
+
logger = logging.getLogger(__name__)
|
| 285 |
+
|
| 286 |
+
# Check if streamlit app exists
|
| 287 |
+
streamlit_files = ["frontend_light.py", "app_enhanced.py", "app.py"]
|
| 288 |
+
streamlit_app = None
|
| 289 |
+
|
| 290 |
+
for file in streamlit_files:
|
| 291 |
+
if os.path.exists(file):
|
| 292 |
+
streamlit_app = file
|
| 293 |
+
break
|
| 294 |
+
|
| 295 |
+
if streamlit_app:
|
| 296 |
+
logger.info(f"Starting Streamlit UI with {streamlit_app}")
|
| 297 |
+
subprocess.run([
|
| 298 |
+
"streamlit", "run", streamlit_app,
|
| 299 |
+
"--server.port=8502",
|
| 300 |
+
"--server.address=0.0.0.0"
|
| 301 |
+
])
|
| 302 |
+
else:
|
| 303 |
+
logger.info("No Streamlit app found. Running FastAPI only (API-only mode)")
|
| 304 |
|
| 305 |
if __name__ == "__main__":
|
| 306 |
+
import logging
|
| 307 |
+
logging.basicConfig(level=logging.INFO)
|
| 308 |
+
logger = logging.getLogger(__name__)
|
| 309 |
+
|
| 310 |
+
# Try to start Streamlit in background (optional)
|
| 311 |
+
streamlit_available = any(os.path.exists(f) for f in ["frontend_light.py", "app_enhanced.py", "app.py"])
|
| 312 |
+
|
| 313 |
+
if streamlit_available:
|
| 314 |
+
logger.info("🎨 Starting Streamlit UI in background...")
|
| 315 |
+
streamlit_thread = Thread(target=run_streamlit, daemon=True)
|
| 316 |
+
streamlit_thread.start()
|
| 317 |
+
else:
|
| 318 |
+
logger.info("📡 Running in API-only mode (no Streamlit UI)")
|
| 319 |
|
| 320 |
# Start FastAPI
|
| 321 |
+
logger.info("🚀 Starting FastAPI server on http://0.0.0.0:7860")
|
| 322 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|