mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-04 17:39:23 +08:00
* Add code * add code * add code * Rename messages * rename * add code * Add demo * docs + demos + bug fixes * add code * styles * user guide * Styles * Add code * misc docs updates * print nit * whisper + pr * url for images * whsiper update * Fix bugs * remove demo files * version number * Fix pypi readme * Fix * demos * Add llama code editor * Update llama code editor and object detection cookbook * Add more cookbook demos * add code * Fix links for PR deploys * add code * Fix the install * add tts * TTS docs * Typo * Pending bubbles for reply on pause * Stream redesign (#63) * better error handling * Websocket error handling * add code --------- Co-authored-by: Freddy Boulton <freddyboulton@hf-freddy.local> * remove docs from dist * Some docs typos * more typos * upload changes + docs * docs * better phone * update docs * add code * Make demos better * fix docs + websocket start_up * remove mention of FastAPI app * fastphone tweaks * add code * ReplyOnStopWord fixes * Fix cookbook * Fix pypi readme * add code * bump versions * sambanova cookbook * Fix tags * Llm voice chat * kyutai tag * Add error message to all index.html * STT module uses Moonshine * Not required from typing extensions * fix llm voice chat * Add vpn warning * demo fixes * demos * Add more ui args and gemini audio-video * update cookbook * version 9 --------- Co-authored-by: Freddy Boulton <freddyboulton@hf-freddy.local>
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
from pathlib import Path
|
|
|
|
import gradio as gr
|
|
from dotenv import load_dotenv
|
|
from fastrtc import WebRTC, get_twilio_turn_credentials
|
|
from gradio.utils import get_space
|
|
|
|
try:
|
|
from demo.llama_code_editor.handler import (
|
|
CodeHandler,
|
|
display_in_sandbox,
|
|
system_prompt,
|
|
)
|
|
except (ImportError, ModuleNotFoundError):
|
|
from handler import CodeHandler, display_in_sandbox, system_prompt
|
|
|
|
load_dotenv()
|
|
|
|
path = Path(__file__).parent / "assets"
|
|
|
|
with gr.Blocks(css=".code-component {max-height: 500px !important}") as demo:
|
|
history = gr.State([{"role": "system", "content": system_prompt}])
|
|
with gr.Row():
|
|
with gr.Column(scale=1):
|
|
gr.HTML(
|
|
"""
|
|
<h1 style='text-align: center'>
|
|
Llama Code Editor
|
|
</h1>
|
|
<h2 style='text-align: center'>
|
|
Powered by SambaNova and Gradio-WebRTC ⚡️
|
|
</h2>
|
|
<p style='text-align: center'>
|
|
Create and edit single-file HTML applications with just your voice!
|
|
</p>
|
|
<p style='text-align: center'>
|
|
Each conversation is limited to 90 seconds. Once the time limit is up you can rejoin the conversation.
|
|
</p>
|
|
"""
|
|
)
|
|
webrtc = WebRTC(
|
|
rtc_configuration=get_twilio_turn_credentials()
|
|
if get_space()
|
|
else None,
|
|
mode="send",
|
|
modality="audio",
|
|
)
|
|
with gr.Column(scale=10):
|
|
with gr.Tabs():
|
|
with gr.Tab("Sandbox"):
|
|
sandbox = gr.HTML(value=open(path / "sandbox.html").read())
|
|
with gr.Tab("Code"):
|
|
code = gr.Code(
|
|
language="html",
|
|
max_lines=50,
|
|
interactive=False,
|
|
elem_classes="code-component",
|
|
)
|
|
with gr.Tab("Chat"):
|
|
cb = gr.Chatbot(type="messages")
|
|
|
|
webrtc.stream(
|
|
CodeHandler,
|
|
inputs=[webrtc, history, code],
|
|
outputs=[webrtc],
|
|
time_limit=90 if get_space() else None,
|
|
concurrency_limit=10 if get_space() else None,
|
|
)
|
|
webrtc.on_additional_outputs(
|
|
lambda history, code: (history, code, history), outputs=[history, code, cb]
|
|
)
|
|
code.change(display_in_sandbox, code, sandbox, queue=False)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|