Spaces:
Sleeping
Sleeping
Commit
·
45ea7ca
1
Parent(s):
de04cb7
Revert portg
Browse files
app.py
CHANGED
|
@@ -930,67 +930,16 @@ def create_app():
|
|
| 930 |
return app
|
| 931 |
|
| 932 |
|
| 933 |
-
# Function to find an available port
|
| 934 |
-
def find_available_port(start_port=7860, max_tries=10):
|
| 935 |
-
"""Find an available port starting from start_port"""
|
| 936 |
-
for port_offset in range(max_tries):
|
| 937 |
-
port = start_port + port_offset
|
| 938 |
-
try:
|
| 939 |
-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 940 |
-
sock.bind(('0.0.0.0', port))
|
| 941 |
-
sock.close()
|
| 942 |
-
return port
|
| 943 |
-
except OSError:
|
| 944 |
-
continue
|
| 945 |
-
# If no ports are available, return a default and let the server handle the error
|
| 946 |
-
return start_port
|
| 947 |
|
| 948 |
|
| 949 |
# Main entry point
|
| 950 |
if __name__ == "__main__":
|
| 951 |
# Create the app
|
| 952 |
app = create_app()
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
available_port = find_available_port(port)
|
| 960 |
-
if available_port != port:
|
| 961 |
-
print(f"Port {port} is in use, using port {available_port} instead.")
|
| 962 |
-
port = available_port
|
| 963 |
-
|
| 964 |
-
print(f"""
|
| 965 |
-
🎤 Real-time Speaker Diarization Server
|
| 966 |
-
=====================================
|
| 967 |
-
|
| 968 |
-
Starting server on: http://{host}:{port}
|
| 969 |
-
|
| 970 |
-
Features:
|
| 971 |
-
- Real-time speech recognition
|
| 972 |
-
- Speaker diarization with color coding
|
| 973 |
-
- FastRTC low-latency audio streaming
|
| 974 |
-
- Web interface for easy interaction
|
| 975 |
-
|
| 976 |
-
Make sure to:
|
| 977 |
-
1. Set HF_TOKEN environment variable for TURN server access
|
| 978 |
-
2. Allow microphone access in your browser
|
| 979 |
-
3. Use a modern browser for best performance
|
| 980 |
-
|
| 981 |
-
API Endpoints:
|
| 982 |
-
- GET /health - Health check
|
| 983 |
-
- GET /api/conversation - Get current conversation
|
| 984 |
-
- POST /api/control/{{action}} - Control recording (start/stop/clear/initialize)
|
| 985 |
-
- WS /stream - FastRTC audio stream endpoint
|
| 986 |
-
|
| 987 |
-
""")
|
| 988 |
-
|
| 989 |
-
# Run the server
|
| 990 |
-
uvicorn.run(
|
| 991 |
-
app,
|
| 992 |
-
host=host,
|
| 993 |
-
port=port,
|
| 994 |
-
log_level="info",
|
| 995 |
-
access_log=True
|
| 996 |
)
|
|
|
|
| 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 |
)
|