@woai
commited on
Commit
·
7600cce
1
Parent(s):
e014546
Fix port conflict: FastAPI on 8000, Gradio on 7860
Browse files- app.py +19 -5
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -19,18 +19,26 @@ from api_server import app as fastapi_app
|
|
| 19 |
|
| 20 |
# Start FastAPI server in background
|
| 21 |
def start_fastapi_server():
|
| 22 |
-
uvicorn.run(fastapi_app, host="0.0.0.0", port=
|
| 23 |
|
| 24 |
# Start FastAPI server in a separate thread
|
| 25 |
server_thread = threading.Thread(target=start_fastapi_server, daemon=True)
|
| 26 |
server_thread.start()
|
| 27 |
|
| 28 |
-
# Wait a moment for server to start
|
| 29 |
import time
|
| 30 |
-
time.sleep(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# API URL for Hugging Face Spaces
|
| 33 |
-
API_URL = "http://localhost:
|
| 34 |
|
| 35 |
async def search_youtube(query, max_results, order, video_duration):
|
| 36 |
"""Function for searching videos on YouTube."""
|
|
@@ -398,4 +406,10 @@ with gr.Blocks(title="YouTube MCP", theme=gr.themes.Soft()) as demo:
|
|
| 398 |
|
| 399 |
# Launch the app
|
| 400 |
if __name__ == "__main__":
|
| 401 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Start FastAPI server in background
|
| 21 |
def start_fastapi_server():
|
| 22 |
+
uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
|
| 23 |
|
| 24 |
# Start FastAPI server in a separate thread
|
| 25 |
server_thread = threading.Thread(target=start_fastapi_server, daemon=True)
|
| 26 |
server_thread.start()
|
| 27 |
|
| 28 |
+
# Wait a moment for server to start and verify it's running
|
| 29 |
import time
|
| 30 |
+
time.sleep(3)
|
| 31 |
+
|
| 32 |
+
# Verify server is running
|
| 33 |
+
try:
|
| 34 |
+
import requests
|
| 35 |
+
response = requests.get("http://localhost:8000/")
|
| 36 |
+
print("✅ FastAPI server is running successfully")
|
| 37 |
+
except Exception as e:
|
| 38 |
+
print(f"⚠️ Warning: FastAPI server may not be ready: {e}")
|
| 39 |
|
| 40 |
# API URL for Hugging Face Spaces
|
| 41 |
+
API_URL = "http://localhost:8000/api"
|
| 42 |
|
| 43 |
async def search_youtube(query, max_results, order, video_duration):
|
| 44 |
"""Function for searching videos on YouTube."""
|
|
|
|
| 406 |
|
| 407 |
# Launch the app
|
| 408 |
if __name__ == "__main__":
|
| 409 |
+
demo.launch(
|
| 410 |
+
server_name="0.0.0.0",
|
| 411 |
+
server_port=7860,
|
| 412 |
+
share=False,
|
| 413 |
+
show_error=True,
|
| 414 |
+
debug=False
|
| 415 |
+
)
|
requirements.txt
CHANGED
|
@@ -2,6 +2,7 @@ fastapi>=0.104.0
|
|
| 2 |
uvicorn>=0.23.2
|
| 3 |
pydantic>=2.4.2
|
| 4 |
httpx>=0.25.0
|
|
|
|
| 5 |
python-dotenv>=1.0.0
|
| 6 |
google-api-python-client>=2.122.0
|
| 7 |
gradio>=4.4.0
|
|
|
|
| 2 |
uvicorn>=0.23.2
|
| 3 |
pydantic>=2.4.2
|
| 4 |
httpx>=0.25.0
|
| 5 |
+
requests>=2.31.0
|
| 6 |
python-dotenv>=1.0.0
|
| 7 |
google-api-python-client>=2.122.0
|
| 8 |
gradio>=4.4.0
|