mi / start_server.py
aheedsajid's picture
Upload 4 files
1cd3ee6 verified
#!/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()