Spaces:
Configuration error
Configuration error
| #!/usr/bin/env python3 | |
| """ | |
| Local startup script for the Real-time Microphone Streaming Server | |
| Use this for local development and testing before deploying to Hugging Face | |
| """ | |
| import os | |
| import sys | |
| import subprocess | |
| import time | |
| def check_dependencies(): | |
| """Check if required packages are installed""" | |
| required_packages = ['gradio', 'websockets', 'numpy'] | |
| missing_packages = [] | |
| for package in required_packages: | |
| try: | |
| __import__(package) | |
| except ImportError: | |
| missing_packages.append(package) | |
| if missing_packages: | |
| print("β Missing required packages:") | |
| for package in missing_packages: | |
| print(f" - {package}") | |
| print("\nπ¦ Installing missing packages...") | |
| try: | |
| subprocess.check_call([sys.executable, '-m', 'pip', 'install'] + missing_packages) | |
| print("β Packages installed successfully!") | |
| except subprocess.CalledProcessError as e: | |
| print(f"β Failed to install packages: {e}") | |
| return False | |
| return True | |
| def main(): | |
| """Main startup function""" | |
| print("π€ Real-time Microphone Streaming Server") | |
| print("=" * 50) | |
| # Check dependencies | |
| print("π Checking dependencies...") | |
| if not check_dependencies(): | |
| print("β Dependency check failed. Exiting.") | |
| sys.exit(1) | |
| print("β Dependencies OK") | |
| # Set environment variables for local development | |
| os.environ['GRADIO_SERVER_NAME'] = '0.0.0.0' | |
| os.environ['GRADIO_SERVER_PORT'] = '7860' | |
| print("\nπ Starting server...") | |
| print("π‘ Gradio interface will be available at: http://localhost:7860") | |
| print("π WebSocket server will be available at: ws://localhost:7861") | |
| print("\nπ± Update your Android app to use: ws://YOUR_LOCAL_IP:7861") | |
| print(" (Replace YOUR_LOCAL_IP with your computer's IP address)") | |
| print("\nβΉοΈ Press Ctrl+C to stop the server") | |
| print("=" * 50) | |
| # Import and run the main app | |
| try: | |
| from app import main as run_app | |
| run_app() | |
| except KeyboardInterrupt: | |
| print("\n\nπ Server stopped by user") | |
| except Exception as e: | |
| print(f"\nβ Server error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| if __name__ == "__main__": | |
| main() | |