Spaces:
Sleeping
Sleeping
Commit
·
4fd1dc7
1
Parent(s):
11f51c7
Fix backend service startup: add websockets and use subprocess for servers
Browse files- app.py +21 -16
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -2740,29 +2740,34 @@ if __name__ == "__main__":
|
|
| 2740 |
# Start backend services if running in HF Spaces
|
| 2741 |
if is_hf_space:
|
| 2742 |
def start_mcp_server():
|
| 2743 |
-
"""Start MCP server in background
|
| 2744 |
try:
|
| 2745 |
-
import
|
| 2746 |
-
|
| 2747 |
-
|
| 2748 |
-
|
| 2749 |
-
|
| 2750 |
-
|
| 2751 |
-
|
| 2752 |
-
|
|
|
|
|
|
|
| 2753 |
except Exception as e:
|
| 2754 |
print(f"Warning: Could not start MCP server: {e}")
|
| 2755 |
|
| 2756 |
def start_fastapi_server():
|
| 2757 |
-
"""Start FastAPI server in background
|
| 2758 |
try:
|
| 2759 |
-
import
|
| 2760 |
-
|
|
|
|
|
|
|
|
|
|
| 2761 |
"backend.api.main:app",
|
| 2762 |
-
host
|
| 2763 |
-
port
|
| 2764 |
-
|
| 2765 |
-
)
|
| 2766 |
except Exception as e:
|
| 2767 |
print(f"Warning: Could not start FastAPI server: {e}")
|
| 2768 |
|
|
|
|
| 2740 |
# Start backend services if running in HF Spaces
|
| 2741 |
if is_hf_space:
|
| 2742 |
def start_mcp_server():
|
| 2743 |
+
"""Start MCP server in background process."""
|
| 2744 |
try:
|
| 2745 |
+
import sys
|
| 2746 |
+
import subprocess
|
| 2747 |
+
# Use subprocess.Popen to run in background
|
| 2748 |
+
subprocess.Popen([
|
| 2749 |
+
sys.executable, "-m", "uvicorn",
|
| 2750 |
+
"backend.mcp_server.server:app",
|
| 2751 |
+
"--host", "0.0.0.0",
|
| 2752 |
+
"--port", os.getenv("MCP_PORT", "8900"),
|
| 2753 |
+
"--log-level", "info"
|
| 2754 |
+
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 2755 |
except Exception as e:
|
| 2756 |
print(f"Warning: Could not start MCP server: {e}")
|
| 2757 |
|
| 2758 |
def start_fastapi_server():
|
| 2759 |
+
"""Start FastAPI server in background process."""
|
| 2760 |
try:
|
| 2761 |
+
import sys
|
| 2762 |
+
import subprocess
|
| 2763 |
+
# Use subprocess.Popen to run in background
|
| 2764 |
+
subprocess.Popen([
|
| 2765 |
+
sys.executable, "-m", "uvicorn",
|
| 2766 |
"backend.api.main:app",
|
| 2767 |
+
"--host", "0.0.0.0",
|
| 2768 |
+
"--port", os.getenv("API_PORT", "8000"),
|
| 2769 |
+
"--log-level", "info"
|
| 2770 |
+
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 2771 |
except Exception as e:
|
| 2772 |
print(f"Warning: Could not start FastAPI server: {e}")
|
| 2773 |
|
requirements.txt
CHANGED
|
@@ -12,6 +12,7 @@ duckduckgo-search
|
|
| 12 |
PyPDF2
|
| 13 |
python-docx
|
| 14 |
python-multipart
|
|
|
|
| 15 |
gradio==4.20.0
|
| 16 |
requests>=2.31.0
|
| 17 |
plotly>=5.0.0
|
|
|
|
| 12 |
PyPDF2
|
| 13 |
python-docx
|
| 14 |
python-multipart
|
| 15 |
+
websockets>=11.0
|
| 16 |
gradio==4.20.0
|
| 17 |
requests>=2.31.0
|
| 18 |
plotly>=5.0.0
|