GradioAgentSpace / gradioui.py
rahuketu86's picture
Upload folder using huggingface_hub
e7320d0 verified
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/book/Agents/01_GradioUI.ipynb.
# %% auto 0
__all__ = ['slow_echo', 'GradioUI']
# %% ../../nbs/book/Agents/01_GradioUI.ipynb 3
from fastcore.all import *
import time
import gradio as gr
# %% ../../nbs/book/Agents/01_GradioUI.ipynb 4
#| eval: false#|exports
#| eval: false
# %% ../../nbs/book/Agents/01_GradioUI.ipynb 5
def slow_echo(message, history, is_multimodal=True):
text_message = message if is_multimodal else message['text']
print(text_message)
for i in range(len(text_message)):
time.sleep(0.05)
yield "You typed: " + text_message[: i + 1]
# %% ../../nbs/book/Agents/01_GradioUI.ipynb 9
class GradioUI(object):
def __init__(self, share=True, multimodal=True):
store_attr()
self.demo = None
def init_demo(self):
self.demo = gr.ChatInterface(fn=slow_echo,
multimodal = self.multimodal,
type='messages',
flagging_mode="manual",
flagging_options=["Like", "Spam", "Inappropriate", "Other"],
save_history=True)
def launch (self):
self.init_demo()
return self.demo.launch(share=self.share)