Spaces:
Sleeping
Sleeping
AshDavid12
commited on
Commit
·
63930f8
1
Parent(s):
a94388a
logging infer
Browse files
client.py
CHANGED
@@ -30,6 +30,17 @@ async def receive_transcription(websocket):
|
|
30 |
print(f"Error receiving transcription: {e}")
|
31 |
break
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
async def run_client():
|
34 |
uri = ("wss://gigaverse-ivrit-ai-streaming.hf.space/ws/transcribe") # WebSocket URL
|
35 |
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
@@ -39,7 +50,8 @@ async def run_client():
|
|
39 |
async with websockets.connect(uri, ssl=ssl_context, timeout=30) as websocket:
|
40 |
await asyncio.gather(
|
41 |
send_audio(websocket),
|
42 |
-
receive_transcription(websocket)
|
|
|
43 |
)
|
44 |
|
45 |
asyncio.run(run_client())
|
|
|
30 |
print(f"Error receiving transcription: {e}")
|
31 |
break
|
32 |
|
33 |
+
async def send_heartbeat(websocket):
|
34 |
+
while True:
|
35 |
+
try:
|
36 |
+
await websocket.ping()
|
37 |
+
print("Sent keepalive ping")
|
38 |
+
except websockets.ConnectionClosed:
|
39 |
+
print("Connection closed, stopping heartbeat")
|
40 |
+
break
|
41 |
+
await asyncio.sleep(30) # Send ping every 30 seconds (adjust as needed)
|
42 |
+
|
43 |
+
|
44 |
async def run_client():
|
45 |
uri = ("wss://gigaverse-ivrit-ai-streaming.hf.space/ws/transcribe") # WebSocket URL
|
46 |
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
|
50 |
async with websockets.connect(uri, ssl=ssl_context, timeout=30) as websocket:
|
51 |
await asyncio.gather(
|
52 |
send_audio(websocket),
|
53 |
+
receive_transcription(websocket),
|
54 |
+
send_heartbeat(websocket)
|
55 |
)
|
56 |
|
57 |
asyncio.run(run_client())
|
infer.py
CHANGED
@@ -12,7 +12,7 @@ from typing import Optional
|
|
12 |
import asyncio
|
13 |
|
14 |
# Configure logging
|
15 |
-
logging.basicConfig(level=logging.INFO, format='%(asctime)s
|
16 |
|
17 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
18 |
logging.info(f'Device selected: {device}')
|
|
|
12 |
import asyncio
|
13 |
|
14 |
# Configure logging
|
15 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s',handlers=[logging.StreamHandler(sys.stdout)])
|
16 |
|
17 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
18 |
logging.info(f'Device selected: {device}')
|