Update server.py
Browse files
server.py
CHANGED
@@ -802,6 +802,10 @@ async def general_exception_handler(request, exc):
|
|
802 |
|
803 |
|
804 |
|
|
|
|
|
|
|
|
|
805 |
import gradio as gr
|
806 |
import threading
|
807 |
import time
|
@@ -908,10 +912,18 @@ def run_workflow_ui(district):
|
|
908 |
|
909 |
# Create CSV file if content exists
|
910 |
if csv_content:
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
915 |
else:
|
916 |
return workflow_output, alert_summary, gr.File(visible=False)
|
917 |
|
@@ -989,7 +1001,6 @@ def run_fastapi():
|
|
989 |
)
|
990 |
|
991 |
if __name__ == "__main__":
|
992 |
-
# Check if we should show UI (HuggingFace Spaces) or just API
|
993 |
if os.getenv("SPACE_ID") or os.getenv("GRADIO_SERVER_NAME"):
|
994 |
# HuggingFace Spaces - start FastAPI in background, Gradio in foreground
|
995 |
logger.info("Starting in HuggingFace Spaces mode with UI...")
|
@@ -1008,6 +1019,5 @@ if __name__ == "__main__":
|
|
1008 |
show_error=True
|
1009 |
)
|
1010 |
else:
|
1011 |
-
# Local development - just run FastAPI
|
1012 |
logger.info("Starting MCP Weather Server (API only)...")
|
1013 |
run_fastapi()
|
|
|
802 |
|
803 |
|
804 |
|
805 |
+
|
806 |
+
# UI
|
807 |
+
|
808 |
+
|
809 |
import gradio as gr
|
810 |
import threading
|
811 |
import time
|
|
|
912 |
|
913 |
# Create CSV file if content exists
|
914 |
if csv_content:
|
915 |
+
import tempfile
|
916 |
+
import os
|
917 |
+
|
918 |
+
# Create temporary file
|
919 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.csv', delete=False, encoding='utf-8') as temp_file:
|
920 |
+
temp_file.write(csv_content)
|
921 |
+
temp_filename = temp_file.name
|
922 |
+
|
923 |
+
# Create a proper filename for download
|
924 |
+
display_name = f"bihar_alert_{district.lower()}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv"
|
925 |
+
|
926 |
+
return workflow_output, alert_summary, gr.File(value=temp_filename, visible=True, label=display_name)
|
927 |
else:
|
928 |
return workflow_output, alert_summary, gr.File(visible=False)
|
929 |
|
|
|
1001 |
)
|
1002 |
|
1003 |
if __name__ == "__main__":
|
|
|
1004 |
if os.getenv("SPACE_ID") or os.getenv("GRADIO_SERVER_NAME"):
|
1005 |
# HuggingFace Spaces - start FastAPI in background, Gradio in foreground
|
1006 |
logger.info("Starting in HuggingFace Spaces mode with UI...")
|
|
|
1019 |
show_error=True
|
1020 |
)
|
1021 |
else:
|
|
|
1022 |
logger.info("Starting MCP Weather Server (API only)...")
|
1023 |
run_fastapi()
|