Spaces:
Sleeping
Sleeping
Commit
·
89943a0
1
Parent(s):
57c1aba
Revert portg
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import urllib.request
|
|
| 9 |
import torchaudio
|
| 10 |
from scipy.spatial.distance import cosine
|
| 11 |
from RealtimeSTT import AudioToTextRecorder
|
| 12 |
-
from fastapi import FastAPI
|
| 13 |
from fastrtc import Stream, AsyncStreamHandler, ReplyOnPause, get_cloudflare_turn_credentials_async, get_cloudflare_turn_credentials
|
| 14 |
import json
|
| 15 |
import io
|
|
@@ -788,6 +788,50 @@ def create_interface():
|
|
| 788 |
return interface
|
| 789 |
|
| 790 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 791 |
# Main application setup
|
| 792 |
def create_app():
|
| 793 |
"""Create and configure the FastAPI app with Gradio and FastRTC"""
|
|
@@ -798,6 +842,9 @@ def create_app():
|
|
| 798 |
version="1.0.0"
|
| 799 |
)
|
| 800 |
|
|
|
|
|
|
|
|
|
|
| 801 |
# Create Gradio interface
|
| 802 |
gradio_interface = create_interface()
|
| 803 |
|
|
@@ -851,47 +898,6 @@ def create_app():
|
|
| 851 |
return app
|
| 852 |
|
| 853 |
|
| 854 |
-
# Health check endpoint
|
| 855 |
-
@app.get("/health")
|
| 856 |
-
async def health_check():
|
| 857 |
-
"""Health check endpoint"""
|
| 858 |
-
return {
|
| 859 |
-
"status": "healthy",
|
| 860 |
-
"timestamp": time.time(),
|
| 861 |
-
"system_initialized": diarization_system.encoder is not None,
|
| 862 |
-
"recording_active": diarization_system.is_running
|
| 863 |
-
}
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
# API endpoint to get conversation
|
| 867 |
-
@app.get("/api/conversation")
|
| 868 |
-
async def get_conversation_api():
|
| 869 |
-
"""API endpoint to get current conversation"""
|
| 870 |
-
return {
|
| 871 |
-
"conversation": diarization_system.get_formatted_conversation(),
|
| 872 |
-
"status": diarization_system.get_status_info(),
|
| 873 |
-
"is_recording": diarization_system.is_running
|
| 874 |
-
}
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
# API endpoint to control recording
|
| 878 |
-
@app.post("/api/control/{action}")
|
| 879 |
-
async def control_recording(action: str):
|
| 880 |
-
"""API endpoint to control recording (start/stop/clear)"""
|
| 881 |
-
if action == "start":
|
| 882 |
-
result = diarization_system.start_recording()
|
| 883 |
-
elif action == "stop":
|
| 884 |
-
result = diarization_system.stop_recording()
|
| 885 |
-
elif action == "clear":
|
| 886 |
-
result = diarization_system.clear_conversation()
|
| 887 |
-
elif action == "initialize":
|
| 888 |
-
result = initialize_system()
|
| 889 |
-
else:
|
| 890 |
-
return {"error": "Invalid action. Use: start, stop, clear, or initialize"}
|
| 891 |
-
|
| 892 |
-
return {"result": result, "is_recording": diarization_system.is_running}
|
| 893 |
-
|
| 894 |
-
|
| 895 |
# Main entry point
|
| 896 |
if __name__ == "__main__":
|
| 897 |
# Create the app
|
|
|
|
| 9 |
import torchaudio
|
| 10 |
from scipy.spatial.distance import cosine
|
| 11 |
from RealtimeSTT import AudioToTextRecorder
|
| 12 |
+
from fastapi import FastAPI, APIRouter
|
| 13 |
from fastrtc import Stream, AsyncStreamHandler, ReplyOnPause, get_cloudflare_turn_credentials_async, get_cloudflare_turn_credentials
|
| 14 |
import json
|
| 15 |
import io
|
|
|
|
| 788 |
return interface
|
| 789 |
|
| 790 |
|
| 791 |
+
# Create API router for endpoints
|
| 792 |
+
router = APIRouter()
|
| 793 |
+
|
| 794 |
+
# Health check endpoint
|
| 795 |
+
@router.get("/health")
|
| 796 |
+
async def health_check():
|
| 797 |
+
"""Health check endpoint"""
|
| 798 |
+
return {
|
| 799 |
+
"status": "healthy",
|
| 800 |
+
"timestamp": time.time(),
|
| 801 |
+
"system_initialized": diarization_system.encoder is not None,
|
| 802 |
+
"recording_active": diarization_system.is_running
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
# API endpoint to get conversation
|
| 807 |
+
@router.get("/api/conversation")
|
| 808 |
+
async def get_conversation_api():
|
| 809 |
+
"""API endpoint to get current conversation"""
|
| 810 |
+
return {
|
| 811 |
+
"conversation": diarization_system.get_formatted_conversation(),
|
| 812 |
+
"status": diarization_system.get_status_info(),
|
| 813 |
+
"is_recording": diarization_system.is_running
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
|
| 817 |
+
# API endpoint to control recording
|
| 818 |
+
@router.post("/api/control/{action}")
|
| 819 |
+
async def control_recording(action: str):
|
| 820 |
+
"""API endpoint to control recording (start/stop/clear)"""
|
| 821 |
+
if action == "start":
|
| 822 |
+
result = diarization_system.start_recording()
|
| 823 |
+
elif action == "stop":
|
| 824 |
+
result = diarization_system.stop_recording()
|
| 825 |
+
elif action == "clear":
|
| 826 |
+
result = diarization_system.clear_conversation()
|
| 827 |
+
elif action == "initialize":
|
| 828 |
+
result = initialize_system()
|
| 829 |
+
else:
|
| 830 |
+
return {"error": "Invalid action. Use: start, stop, clear, or initialize"}
|
| 831 |
+
|
| 832 |
+
return {"result": result, "is_recording": diarization_system.is_running}
|
| 833 |
+
|
| 834 |
+
|
| 835 |
# Main application setup
|
| 836 |
def create_app():
|
| 837 |
"""Create and configure the FastAPI app with Gradio and FastRTC"""
|
|
|
|
| 842 |
version="1.0.0"
|
| 843 |
)
|
| 844 |
|
| 845 |
+
# Include API routes
|
| 846 |
+
app.include_router(router)
|
| 847 |
+
|
| 848 |
# Create Gradio interface
|
| 849 |
gradio_interface = create_interface()
|
| 850 |
|
|
|
|
| 898 |
return app
|
| 899 |
|
| 900 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 901 |
# Main entry point
|
| 902 |
if __name__ == "__main__":
|
| 903 |
# Create the app
|