File size: 2,430 Bytes
0f4801b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/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()