#!/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()