mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
Initial
This commit is contained in:
@@ -58,3 +58,4 @@ httpx==0.24.1
|
|||||||
sortedcontainers==2.4.0
|
sortedcontainers==2.4.0
|
||||||
https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
|
https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
|
||||||
gpt4all==1.0.5
|
gpt4all==1.0.5
|
||||||
|
aiohttp_cors
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import uuid
|
|||||||
import wave
|
import wave
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
|
import aiohttp_cors
|
||||||
import jax.numpy as jnp
|
import jax.numpy as jnp
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription
|
from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription
|
||||||
@@ -14,14 +15,12 @@ from gpt4all import GPT4All
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
from whisper_jax import FlaxWhisperPipline
|
from whisper_jax import FlaxWhisperPipline
|
||||||
|
|
||||||
from utils.run_utils import run_in_executor, config
|
from utils.run_utils import config, run_in_executor
|
||||||
|
|
||||||
pcs = set()
|
pcs = set()
|
||||||
relay = MediaRelay()
|
relay = MediaRelay()
|
||||||
data_channel = None
|
data_channel = None
|
||||||
pipeline = FlaxWhisperPipline("openai/whisper-tiny",
|
pipeline = FlaxWhisperPipline("openai/whisper-tiny", dtype=jnp.float16, batch_size=16)
|
||||||
dtype=jnp.float16,
|
|
||||||
batch_size=16)
|
|
||||||
|
|
||||||
CHANNELS = 2
|
CHANNELS = 2
|
||||||
RATE = 48000
|
RATE = 48000
|
||||||
@@ -103,8 +102,7 @@ class AudioStreamTrack(MediaStreamTrack):
|
|||||||
if f.result()
|
if f.result()
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
llm_result = run_in_executor(get_title_and_summary,
|
llm_result = run_in_executor(get_title_and_summary, executor=executor)
|
||||||
executor=executor)
|
|
||||||
llm_result.add_done_callback(
|
llm_result.add_done_callback(
|
||||||
lambda f: channel_send(data_channel, llm_result.result())
|
lambda f: channel_send(data_channel, llm_result.result())
|
||||||
if f.result()
|
if f.result()
|
||||||
@@ -158,8 +156,7 @@ async def offer(request):
|
|||||||
return web.Response(
|
return web.Response(
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
text=json.dumps(
|
text=json.dumps(
|
||||||
{"sdp": pc.localDescription.sdp,
|
{"sdp": pc.localDescription.sdp, "type": pc.localDescription.type}
|
||||||
"type": pc.localDescription.type}
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -172,6 +169,17 @@ async def on_shutdown(app):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
|
|
||||||
|
cors = aiohttp_cors.setup(
|
||||||
|
app,
|
||||||
|
defaults={
|
||||||
|
"*": aiohttp_cors.ResourceOptions(
|
||||||
|
allow_credentials=True, expose_headers="*", allow_headers="*"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
offer_resource = cors.add(app.router.add_resource("/offer"))
|
||||||
|
cors.add(offer_resource.add_route("POST", offer))
|
||||||
app.on_shutdown.append(on_shutdown)
|
app.on_shutdown.append(on_shutdown)
|
||||||
app.router.add_post("/offer", offer)
|
|
||||||
web.run_app(app, access_log=None, host="127.0.0.1", port=1250)
|
web.run_app(app, access_log=None, host="127.0.0.1", port=1250)
|
||||||
|
|||||||
Reference in New Issue
Block a user