nuernie
commited on
Commit
·
28ad8e5
1
Parent(s):
e45ca79
app adjusts
Browse files- app.py +41 -12
- requirements.txt +16 -8
app.py
CHANGED
@@ -1,19 +1,48 @@
|
|
1 |
-
from fastapi import FastAPI
|
|
|
2 |
import uvicorn
|
3 |
from whisper_live.server import TranscriptionServer
|
|
|
4 |
|
5 |
-
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
@app.get("/health")
|
19 |
def health_check():
|
|
|
1 |
+
from fastapi import FastAPI, WebSocket
|
2 |
+
from contextlib import asynccontextmanager
|
3 |
import uvicorn
|
4 |
from whisper_live.server import TranscriptionServer
|
5 |
+
import logging
|
6 |
|
7 |
+
# Configure logging
|
8 |
+
logging.basicConfig(level=logging.INFO)
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
|
11 |
+
# Initialize the transcription server
|
12 |
+
transcription_server = TranscriptionServer()
|
13 |
+
|
14 |
+
@asynccontextmanager
|
15 |
+
async def lifespan(app: FastAPI):
|
16 |
+
# Any startup configuration can go here
|
17 |
+
yield
|
18 |
+
# Cleanup can go here if needed
|
19 |
+
|
20 |
+
app = FastAPI(title="Whisper Live Server", lifespan=lifespan)
|
21 |
+
|
22 |
+
@app.websocket("/ws")
|
23 |
+
async def websocket_endpoint(websocket: WebSocket):
|
24 |
+
await websocket.accept()
|
25 |
+
try:
|
26 |
+
# Start the transcription server with the WebSocket connection
|
27 |
+
transcription_server.run(
|
28 |
+
host="0.0.0.0",
|
29 |
+
port=7860, # Hugging Face Spaces uses port 7860
|
30 |
+
backend="faster_whisper", # Using faster_whisper as the backend
|
31 |
+
single_model=True # Use single model mode for better resource usage
|
32 |
+
)
|
33 |
+
|
34 |
+
# Handle WebSocket communication
|
35 |
+
while True:
|
36 |
+
data = await websocket.receive()
|
37 |
+
if data.get("type") == "websocket.disconnect":
|
38 |
+
break
|
39 |
+
# Process the received data through the transcription server
|
40 |
+
# Note: You might need to adapt this part based on your specific needs
|
41 |
+
await websocket.send_text(data)
|
42 |
+
except Exception as e:
|
43 |
+
logger.error(f"WebSocket error: {e}")
|
44 |
+
finally:
|
45 |
+
await websocket.close()
|
46 |
|
47 |
@app.get("/health")
|
48 |
def health_check():
|
requirements.txt
CHANGED
@@ -1,9 +1,17 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
websockets
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
soundfile
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
1 |
+
fastapi>=0.68.0
|
2 |
+
uvicorn>=0.15.0
|
3 |
+
websockets>=10.0
|
4 |
+
numpy>=1.21.0
|
5 |
+
faster-whisper==1.1.0
|
6 |
+
PyAudio
|
7 |
+
websocket-client
|
8 |
+
numba
|
9 |
+
kaldialign
|
10 |
soundfile
|
11 |
+
tokenizers==0.20.3
|
12 |
+
librosa
|
13 |
+
openvino
|
14 |
+
openvino-genai
|
15 |
+
openvino-tokenizers
|
16 |
+
optimum
|
17 |
+
optimum-intel
|