Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload folder using huggingface_hub
Browse files- app.py +21 -14
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,28 +1,29 @@
|
|
| 1 |
import asyncio
|
| 2 |
import base64
|
|
|
|
|
|
|
| 3 |
import pathlib
|
| 4 |
from typing import AsyncGenerator, Literal
|
|
|
|
|
|
|
|
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from google import genai
|
| 8 |
-
from pydantic import BaseModel
|
| 9 |
from google.genai.types import (
|
| 10 |
LiveConnectConfig,
|
| 11 |
PrebuiltVoiceConfig,
|
| 12 |
SpeechConfig,
|
| 13 |
VoiceConfig,
|
| 14 |
)
|
| 15 |
-
import gradio as gr
|
| 16 |
-
import json
|
| 17 |
from gradio.utils import get_space
|
| 18 |
-
from
|
| 19 |
-
Stream,
|
| 20 |
-
AsyncStreamHandler,
|
| 21 |
-
async_aggregate_bytes_to_16bit,
|
| 22 |
-
get_twilio_turn_credentials,
|
| 23 |
-
)
|
| 24 |
-
import numpy as np
|
| 25 |
-
from fastapi.responses import HTMLResponse
|
| 26 |
|
| 27 |
current_dir = pathlib.Path(__file__).parent
|
| 28 |
|
|
@@ -67,7 +68,7 @@ class GeminiHandler(AsyncStreamHandler):
|
|
| 67 |
return
|
| 68 |
|
| 69 |
async def connect(
|
| 70 |
-
self, api_key: str | None = None, voice_name: str | None =
|
| 71 |
) -> AsyncGenerator[bytes, None]:
|
| 72 |
"""Connect to to genai server and start the stream"""
|
| 73 |
client = genai.Client(
|
|
@@ -124,6 +125,7 @@ stream = Stream(
|
|
| 124 |
mode="send-receive",
|
| 125 |
handler=GeminiHandler(),
|
| 126 |
rtc_configuration=get_twilio_turn_credentials() if get_space() else None,
|
|
|
|
| 127 |
additional_inputs=[
|
| 128 |
gr.Textbox(label="API Key", type="password", value=os.getenv("GEMINI_API_KEY")),
|
| 129 |
gr.Dropdown(
|
|
@@ -162,6 +164,11 @@ async def index():
|
|
| 162 |
|
| 163 |
|
| 164 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 165 |
import uvicorn
|
| 166 |
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import base64
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
import pathlib
|
| 6 |
from typing import AsyncGenerator, Literal
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import numpy as np
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
+
from fastapi.responses import HTMLResponse
|
| 12 |
+
from fastrtc import (
|
| 13 |
+
AsyncStreamHandler,
|
| 14 |
+
Stream,
|
| 15 |
+
async_aggregate_bytes_to_16bit,
|
| 16 |
+
get_twilio_turn_credentials,
|
| 17 |
+
)
|
| 18 |
from google import genai
|
|
|
|
| 19 |
from google.genai.types import (
|
| 20 |
LiveConnectConfig,
|
| 21 |
PrebuiltVoiceConfig,
|
| 22 |
SpeechConfig,
|
| 23 |
VoiceConfig,
|
| 24 |
)
|
|
|
|
|
|
|
| 25 |
from gradio.utils import get_space
|
| 26 |
+
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
current_dir = pathlib.Path(__file__).parent
|
| 29 |
|
|
|
|
| 68 |
return
|
| 69 |
|
| 70 |
async def connect(
|
| 71 |
+
self, api_key: str | None = None, voice_name: str | None = "Kore"
|
| 72 |
) -> AsyncGenerator[bytes, None]:
|
| 73 |
"""Connect to to genai server and start the stream"""
|
| 74 |
client = genai.Client(
|
|
|
|
| 125 |
mode="send-receive",
|
| 126 |
handler=GeminiHandler(),
|
| 127 |
rtc_configuration=get_twilio_turn_credentials() if get_space() else None,
|
| 128 |
+
concurrency_limit=20 if get_space() else None,
|
| 129 |
additional_inputs=[
|
| 130 |
gr.Textbox(label="API Key", type="password", value=os.getenv("GEMINI_API_KEY")),
|
| 131 |
gr.Dropdown(
|
|
|
|
| 164 |
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
| 167 |
+
import os
|
| 168 |
+
|
| 169 |
import uvicorn
|
| 170 |
|
| 171 |
+
if os.getenv("FASTPHONE"):
|
| 172 |
+
stream.fastphone(host="0.0.0.0", port=7860)
|
| 173 |
+
else:
|
| 174 |
+
uvicorn.run(stream, host="0.0.0.0", port=7860)
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
fastrtc
|
| 2 |
python-dotenv
|
| 3 |
google-genai
|
| 4 |
twilio
|
|
|
|
| 1 |
+
fastrtc
|
| 2 |
python-dotenv
|
| 3 |
google-genai
|
| 4 |
twilio
|