Spaces:
Sleeping
Sleeping
Update run.py
Browse files
run.py
CHANGED
|
@@ -5,8 +5,8 @@ Provides CLI interface and server startup.
|
|
| 5 |
|
| 6 |
import sys
|
| 7 |
import argparse
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
-
import os # Added to read environment variables
|
| 10 |
|
| 11 |
# Import necessary modules for server and middleware
|
| 12 |
from src.utils.logger import setup_logger
|
|
@@ -32,8 +32,11 @@ def run_server():
|
|
| 32 |
allow_headers=["*"], # Allows all headers
|
| 33 |
)
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
#
|
|
|
|
|
|
|
|
|
|
| 37 |
port = int(os.environ.get("PORT", 7860))
|
| 38 |
|
| 39 |
logger.info("Starting YouTube Study Notes AI server...")
|
|
@@ -41,17 +44,13 @@ def run_server():
|
|
| 41 |
logger.info(f"API Documentation: http://0.0.0.0:{port}/docs")
|
| 42 |
|
| 43 |
# Run the server using the app object directly
|
| 44 |
-
#
|
| 45 |
uvicorn.run(app, host="0.0.0.0", port=port, log_level="info")
|
| 46 |
|
| 47 |
|
| 48 |
def run_cli(youtube_url: str, output_file: str = None):
|
| 49 |
"""
|
| 50 |
Run note generation from command line.
|
| 51 |
-
|
| 52 |
-
Args:
|
| 53 |
-
youtube_url: YouTube video URL
|
| 54 |
-
output_file: Optional output file path
|
| 55 |
"""
|
| 56 |
from src.audio.downloader import YouTubeDownloader
|
| 57 |
from src.transcription.whisper_transcriber import WhisperTranscriber
|
|
|
|
| 5 |
|
| 6 |
import sys
|
| 7 |
import argparse
|
| 8 |
+
import os
|
| 9 |
from pathlib import Path
|
|
|
|
| 10 |
|
| 11 |
# Import necessary modules for server and middleware
|
| 12 |
from src.utils.logger import setup_logger
|
|
|
|
| 32 |
allow_headers=["*"], # Allows all headers
|
| 33 |
)
|
| 34 |
|
| 35 |
+
# ---------------------------------------------------------
|
| 36 |
+
# TWEAK FOR HUGGING FACE SPACES
|
| 37 |
+
# Hugging Face sets the 'PORT' environment variable to 7860.
|
| 38 |
+
# We use it if available, otherwise fallback to 7860 default.
|
| 39 |
+
# ---------------------------------------------------------
|
| 40 |
port = int(os.environ.get("PORT", 7860))
|
| 41 |
|
| 42 |
logger.info("Starting YouTube Study Notes AI server...")
|
|
|
|
| 44 |
logger.info(f"API Documentation: http://0.0.0.0:{port}/docs")
|
| 45 |
|
| 46 |
# Run the server using the app object directly
|
| 47 |
+
# Host must be "0.0.0.0" to be accessible externally
|
| 48 |
uvicorn.run(app, host="0.0.0.0", port=port, log_level="info")
|
| 49 |
|
| 50 |
|
| 51 |
def run_cli(youtube_url: str, output_file: str = None):
|
| 52 |
"""
|
| 53 |
Run note generation from command line.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
"""
|
| 55 |
from src.audio.downloader import YouTubeDownloader
|
| 56 |
from src.transcription.whisper_transcriber import WhisperTranscriber
|