ShivamPansuriya
commited on
Commit
·
00544a8
1
Parent(s):
ad19ffc
fix
Browse files
__pycache__/app.cpython-39.pyc
ADDED
|
Binary file (11 kB). View file
|
|
|
__pycache__/config.cpython-39.pyc
ADDED
|
Binary file (1.04 kB). View file
|
|
|
__pycache__/models.cpython-39.pyc
ADDED
|
Binary file (1.66 kB). View file
|
|
|
__pycache__/storage.cpython-39.pyc
ADDED
|
Binary file (5.93 kB). View file
|
|
|
__pycache__/transcription_service.cpython-39.pyc
ADDED
|
Binary file (9.12 kB). View file
|
|
|
app.py
CHANGED
|
@@ -10,6 +10,7 @@ import threading
|
|
| 10 |
import time
|
| 11 |
import os
|
| 12 |
import logging
|
|
|
|
| 13 |
from datetime import datetime
|
| 14 |
from typing import Optional, Tuple
|
| 15 |
import uvicorn
|
|
@@ -24,6 +25,24 @@ from storage import storage
|
|
| 24 |
from transcription_service import transcription_service
|
| 25 |
from logging_config import setup_logging, log_step, log_success, log_error
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Setup logging for Hugging Face Spaces
|
| 28 |
setup_logging(level=logging.INFO, log_to_file=False)
|
| 29 |
logger = logging.getLogger(__name__)
|
|
@@ -317,26 +336,33 @@ async def startup():
|
|
| 317 |
else:
|
| 318 |
log_error("Model preload failed")
|
| 319 |
|
| 320 |
-
def run_fastapi():
|
| 321 |
"""Run FastAPI in a separate thread"""
|
| 322 |
-
|
|
|
|
|
|
|
|
|
|
| 323 |
|
| 324 |
# Main execution
|
| 325 |
if __name__ == "__main__":
|
| 326 |
# Run startup
|
| 327 |
asyncio.run(startup())
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
# Start FastAPI in background thread for API access
|
| 330 |
-
api_thread = threading.Thread(target=run_fastapi, daemon=True)
|
| 331 |
api_thread.start()
|
| 332 |
-
|
| 333 |
# Create and launch Gradio interface
|
| 334 |
interface = create_gradio_interface()
|
| 335 |
-
|
| 336 |
# Launch with API access enabled
|
| 337 |
interface.launch(
|
| 338 |
server_name="0.0.0.0",
|
| 339 |
-
server_port=
|
| 340 |
share=False, # HF Spaces handles sharing
|
| 341 |
show_api=True, # Enable API documentation
|
| 342 |
show_error=True
|
|
|
|
| 10 |
import time
|
| 11 |
import os
|
| 12 |
import logging
|
| 13 |
+
import socket
|
| 14 |
from datetime import datetime
|
| 15 |
from typing import Optional, Tuple
|
| 16 |
import uvicorn
|
|
|
|
| 25 |
from transcription_service import transcription_service
|
| 26 |
from logging_config import setup_logging, log_step, log_success, log_error
|
| 27 |
|
| 28 |
+
def find_available_port(start_port=7860, max_attempts=100):
|
| 29 |
+
"""Find an available port starting from start_port"""
|
| 30 |
+
for port in range(start_port, start_port + max_attempts):
|
| 31 |
+
try:
|
| 32 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
| 33 |
+
s.bind(('0.0.0.0', port))
|
| 34 |
+
log_success(f"Found available port: {port}")
|
| 35 |
+
return port
|
| 36 |
+
except OSError:
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
# If no port found in range, try system-assigned port
|
| 40 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
| 41 |
+
s.bind(('0.0.0.0', 0))
|
| 42 |
+
port = s.getsockname()[1]
|
| 43 |
+
log_success(f"Using system-assigned port: {port}")
|
| 44 |
+
return port
|
| 45 |
+
|
| 46 |
# Setup logging for Hugging Face Spaces
|
| 47 |
setup_logging(level=logging.INFO, log_to_file=False)
|
| 48 |
logger = logging.getLogger(__name__)
|
|
|
|
| 336 |
else:
|
| 337 |
log_error("Model preload failed")
|
| 338 |
|
| 339 |
+
def run_fastapi(port=None):
|
| 340 |
"""Run FastAPI in a separate thread"""
|
| 341 |
+
if port is None:
|
| 342 |
+
port = find_available_port(7860)
|
| 343 |
+
log_step(f"Starting FastAPI server on port {port}")
|
| 344 |
+
uvicorn.run(api_app, host="0.0.0.0", port=port, log_level="info")
|
| 345 |
|
| 346 |
# Main execution
|
| 347 |
if __name__ == "__main__":
|
| 348 |
# Run startup
|
| 349 |
asyncio.run(startup())
|
| 350 |
+
|
| 351 |
+
# Find available port
|
| 352 |
+
available_port = find_available_port(7860)
|
| 353 |
+
log_step(f"Using port {available_port} for both FastAPI and Gradio")
|
| 354 |
+
|
| 355 |
# Start FastAPI in background thread for API access
|
| 356 |
+
api_thread = threading.Thread(target=run_fastapi, args=(available_port,), daemon=True)
|
| 357 |
api_thread.start()
|
| 358 |
+
|
| 359 |
# Create and launch Gradio interface
|
| 360 |
interface = create_gradio_interface()
|
| 361 |
+
|
| 362 |
# Launch with API access enabled
|
| 363 |
interface.launch(
|
| 364 |
server_name="0.0.0.0",
|
| 365 |
+
server_port=available_port,
|
| 366 |
share=False, # HF Spaces handles sharing
|
| 367 |
show_api=True, # Enable API documentation
|
| 368 |
show_error=True
|
hf_spaces_deploy/app.py
CHANGED
|
@@ -10,6 +10,7 @@ import threading
|
|
| 10 |
import time
|
| 11 |
import os
|
| 12 |
import logging
|
|
|
|
| 13 |
from datetime import datetime
|
| 14 |
from typing import Optional, Tuple
|
| 15 |
import uvicorn
|
|
@@ -24,6 +25,24 @@ from storage import storage
|
|
| 24 |
from transcription_service import transcription_service
|
| 25 |
from logging_config import setup_logging, log_step, log_success, log_error
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Setup logging for Hugging Face Spaces
|
| 28 |
setup_logging(level=logging.INFO, log_to_file=False)
|
| 29 |
logger = logging.getLogger(__name__)
|
|
@@ -317,26 +336,33 @@ async def startup():
|
|
| 317 |
else:
|
| 318 |
log_error("Model preload failed")
|
| 319 |
|
| 320 |
-
def run_fastapi():
|
| 321 |
"""Run FastAPI in a separate thread"""
|
| 322 |
-
|
|
|
|
|
|
|
|
|
|
| 323 |
|
| 324 |
# Main execution
|
| 325 |
if __name__ == "__main__":
|
| 326 |
# Run startup
|
| 327 |
asyncio.run(startup())
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
# Start FastAPI in background thread for API access
|
| 330 |
-
api_thread = threading.Thread(target=run_fastapi, daemon=True)
|
| 331 |
api_thread.start()
|
| 332 |
-
|
| 333 |
# Create and launch Gradio interface
|
| 334 |
interface = create_gradio_interface()
|
| 335 |
-
|
| 336 |
# Launch with API access enabled
|
| 337 |
interface.launch(
|
| 338 |
server_name="0.0.0.0",
|
| 339 |
-
server_port=
|
| 340 |
share=False, # HF Spaces handles sharing
|
| 341 |
show_api=True, # Enable API documentation
|
| 342 |
show_error=True
|
|
|
|
| 10 |
import time
|
| 11 |
import os
|
| 12 |
import logging
|
| 13 |
+
import socket
|
| 14 |
from datetime import datetime
|
| 15 |
from typing import Optional, Tuple
|
| 16 |
import uvicorn
|
|
|
|
| 25 |
from transcription_service import transcription_service
|
| 26 |
from logging_config import setup_logging, log_step, log_success, log_error
|
| 27 |
|
| 28 |
+
def find_available_port(start_port=7860, max_attempts=100):
|
| 29 |
+
"""Find an available port starting from start_port"""
|
| 30 |
+
for port in range(start_port, start_port + max_attempts):
|
| 31 |
+
try:
|
| 32 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
| 33 |
+
s.bind(('0.0.0.0', port))
|
| 34 |
+
log_success(f"Found available port: {port}")
|
| 35 |
+
return port
|
| 36 |
+
except OSError:
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
# If no port found in range, try system-assigned port
|
| 40 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
| 41 |
+
s.bind(('0.0.0.0', 0))
|
| 42 |
+
port = s.getsockname()[1]
|
| 43 |
+
log_success(f"Using system-assigned port: {port}")
|
| 44 |
+
return port
|
| 45 |
+
|
| 46 |
# Setup logging for Hugging Face Spaces
|
| 47 |
setup_logging(level=logging.INFO, log_to_file=False)
|
| 48 |
logger = logging.getLogger(__name__)
|
|
|
|
| 336 |
else:
|
| 337 |
log_error("Model preload failed")
|
| 338 |
|
| 339 |
+
def run_fastapi(port=None):
|
| 340 |
"""Run FastAPI in a separate thread"""
|
| 341 |
+
if port is None:
|
| 342 |
+
port = find_available_port(7860)
|
| 343 |
+
log_step(f"Starting FastAPI server on port {port}")
|
| 344 |
+
uvicorn.run(api_app, host="0.0.0.0", port=port, log_level="info")
|
| 345 |
|
| 346 |
# Main execution
|
| 347 |
if __name__ == "__main__":
|
| 348 |
# Run startup
|
| 349 |
asyncio.run(startup())
|
| 350 |
+
|
| 351 |
+
# Find available port
|
| 352 |
+
available_port = find_available_port(7860)
|
| 353 |
+
log_step(f"Using port {available_port} for both FastAPI and Gradio")
|
| 354 |
+
|
| 355 |
# Start FastAPI in background thread for API access
|
| 356 |
+
api_thread = threading.Thread(target=run_fastapi, args=(available_port,), daemon=True)
|
| 357 |
api_thread.start()
|
| 358 |
+
|
| 359 |
# Create and launch Gradio interface
|
| 360 |
interface = create_gradio_interface()
|
| 361 |
+
|
| 362 |
# Launch with API access enabled
|
| 363 |
interface.launch(
|
| 364 |
server_name="0.0.0.0",
|
| 365 |
+
server_port=available_port,
|
| 366 |
share=False, # HF Spaces handles sharing
|
| 367 |
show_api=True, # Enable API documentation
|
| 368 |
show_error=True
|