File size: 1,844 Bytes
1a3844d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
def greet(name):
return "Hello " + name + "!!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()
# import asyncio
# from gradio_webrtc import AsyncAudioVideoStreamHandler
# class GeminiHandler(AsyncAudioVideoStreamHandler):
# def __init__(
# self, expected_layout="mono", output_sample_rate=24000, output_frame_size=480
# ) -> None:
# super().__init__(
# expected_layout,
# output_sample_rate,
# output_frame_size,
# input_sample_rate=16000,
# )
# self.audio_queue = asyncio.Queue()
# self.video_queue = asyncio.Queue()
# self.quit = asyncio.Event()
# self.session = None
# self.last_frame_time = 0
# def copy(self) -> "GeminiHandler":
# """Copy gets called whenever a new user connects to the server.
# This ensures that each user has an independent handler.
# """
# return GeminiHandler(
# expected_layout=self.expected_layout,
# output_sample_rate=self.output_sample_rate,
# output_frame_size=self.output_frame_size,
# )
# async def video_receive(self, frame: np.ndarray):
# """Send video frames to the server"""
# if self.session:
# # send image every 1 second
# # otherwise we flood the API
# if time.time() - self.last_frame_time > 1:
# self.last_frame_time = time.time()
# await self.session.send(encode_image(frame))
# if self.latest_args[2] is not None:
# await self.session.send(encode_image(self.latest_args[2]))
# self.video_queue.put_nowait(frame)
# async def video_emit(self) -> VideoEmitType:
# """Return video frames to the client"""
# return await self.video_queue.get() |