mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 18:09:23 +08:00
Add text mode (#321)
* Pretty good spot * Working draft * Fix other mode * Add js to git * Working * Add code * fix * Fix * Add code * Fix submit race condition * demo * fix * Fix * Fix
This commit is contained in:
@@ -42,6 +42,7 @@ from fastrtc.utils import (
|
||||
AdditionalOutputs,
|
||||
Context,
|
||||
RTCConfigurationCallable,
|
||||
WebRTCData,
|
||||
create_message,
|
||||
webrtc_error_handler,
|
||||
)
|
||||
@@ -151,6 +152,20 @@ class WebRTCConnectionMixin:
|
||||
for conn in self.connections[webrtc_id]:
|
||||
conn.set_args(list(args))
|
||||
|
||||
def set_input_gradio(self, webrtc_data: WebRTCData | str, *args):
|
||||
webrtc_id = webrtc_data
|
||||
if isinstance(webrtc_data, WebRTCData):
|
||||
webrtc_id = webrtc_data.webrtc_id
|
||||
self.set_input(cast(str, webrtc_id), webrtc_data, *args)
|
||||
|
||||
def set_input_on_submit(self, webrtc_data: WebRTCData | str, *args):
|
||||
webrtc_id = webrtc_data
|
||||
if isinstance(webrtc_data, WebRTCData):
|
||||
webrtc_id = webrtc_data.webrtc_id
|
||||
self.set_input(cast(str, webrtc_id), webrtc_data, *args)
|
||||
if hasattr(self.handlers[cast(str, webrtc_id)], "trigger_response"):
|
||||
self.handlers[cast(str, webrtc_id)].trigger_response() # type: ignore
|
||||
|
||||
async def output_stream(
|
||||
self, webrtc_id: str
|
||||
) -> AsyncGenerator[AdditionalOutputs, None]:
|
||||
@@ -182,6 +197,19 @@ class WebRTCConnectionMixin:
|
||||
else:
|
||||
return cast(dict[str, Any], self.rtc_configuration) or {}
|
||||
|
||||
async def _trigger_response(self, webrtc_id: str, args: list[Any] | None = None):
|
||||
from fastrtc import ReplyOnPause
|
||||
|
||||
if webrtc_id in self.connections and isinstance(
|
||||
self.handlers[webrtc_id], ReplyOnPause
|
||||
):
|
||||
if args:
|
||||
cast(ReplyOnPause, self.handlers[webrtc_id]).set_args(args)
|
||||
cast(ReplyOnPause, self.handlers[webrtc_id]).trigger_response()
|
||||
return {"status": "success"}
|
||||
else:
|
||||
return {"status": "failed", "meta": {"error": "not_a_reply_on_pause"}}
|
||||
|
||||
async def handle_offer(self, body, set_outputs):
|
||||
logger.debug("Starting to handle offer")
|
||||
logger.debug("Offer body %s", body)
|
||||
|
||||
Reference in New Issue
Block a user