Saiyaswanth007 commited on
Commit
8b75eaf
·
1 Parent(s): 45ea7ca

Revert portg

Browse files
Files changed (1) hide show
  1. app.py +59 -10
app.py CHANGED
@@ -918,8 +918,8 @@ def create_app():
918
  mode="send-receive"
919
  )
920
 
921
- # Add FastRTC endpoints
922
- app.mount("/stream", stream)
923
 
924
  print("FastRTC stream configured successfully!")
925
 
@@ -930,16 +930,65 @@ def create_app():
930
  return app
931
 
932
 
933
-
934
-
935
  # Main entry point
936
  if __name__ == "__main__":
937
  # Create the app
938
  app = create_app()
939
- interface = create_interface()
940
- # Simple launch - HF Spaces will handle host/port automatically
941
- interface.launch(
942
- share=False, # Not needed in HF Spaces
943
- server_name="0.0.0.0", # Required for HF Spaces
944
- # Don't specify server_port - let HF Spaces handle it
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
945
  )
 
918
  mode="send-receive"
919
  )
920
 
921
+ # Mount the FastRTC stream to the FastAPI app
922
+ stream.mount(app)
923
 
924
  print("FastRTC stream configured successfully!")
925
 
 
930
  return app
931
 
932
 
 
 
933
  # Main entry point
934
  if __name__ == "__main__":
935
  # Create the app
936
  app = create_app()
937
+
938
+ # Configuration
939
+ host = os.environ.get("HOST", "0.0.0.0")
940
+ port = int(os.environ.get("PORT", 7860))
941
+
942
+ # Find available port if specified port is in use
943
+ def find_available_port(start_port=7860, max_tries=10):
944
+ """Find an available port starting from start_port"""
945
+ for port_offset in range(max_tries):
946
+ port = start_port + port_offset
947
+ try:
948
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
949
+ sock.bind(('0.0.0.0', port))
950
+ sock.close()
951
+ return port
952
+ except OSError:
953
+ continue
954
+ # If no ports are available, return a default and let the server handle the error
955
+ return start_port
956
+
957
+ available_port = find_available_port(port)
958
+ if available_port != port:
959
+ print(f"Port {port} is in use, using port {available_port} instead.")
960
+ port = available_port
961
+
962
+ print(f"""
963
+ 🎤 Real-time Speaker Diarization Server
964
+ =====================================
965
+
966
+ Starting server on: http://{host}:{port}
967
+
968
+ Features:
969
+ - Real-time speech recognition
970
+ - Speaker diarization with color coding
971
+ - FastRTC low-latency audio streaming
972
+ - Web interface for easy interaction
973
+
974
+ Make sure to:
975
+ 1. Set HF_TOKEN environment variable for TURN server access
976
+ 2. Allow microphone access in your browser
977
+ 3. Use a modern browser for best performance
978
+
979
+ API Endpoints:
980
+ - GET /health - Health check
981
+ - GET /api/conversation - Get current conversation
982
+ - POST /api/control/{action} - Control recording (start/stop/clear/initialize)
983
+ - WS /stream/webrtc - FastRTC WebRTC endpoint
984
+
985
+ """)
986
+
987
+ # Run the server
988
+ uvicorn.run(
989
+ app,
990
+ host=host,
991
+ port=port,
992
+ log_level="info",
993
+ access_log=True
994
  )