File size: 1,219 Bytes
0b8e564
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7320d0
 
 
 
 
0b8e564
e7320d0
0b8e564
e7320d0
0b8e564
e7320d0
0b8e564
e7320d0
 
 
 
 
 
 
 
 
 
0b8e564
 
e7320d0
 
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
# 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)