File size: 1,257 Bytes
bdfad5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from main import chat, index_url

"""Use text to call chat method from main.py"""
def add_text(history, text):
    response = str(chat(question=text))
    history = history + [(text, response)]
    return history, ""

"""Use text to call index_url method from main.py"""
def add_url(history, url):
    data = index_url(url)
    response = "Found your data!"
    history = history + [(url, response)]
    return history, ""

def bot(history):
    return history

with gr.Blocks() as demo:
    chatbot = gr.Chatbot([], elem_id="chatbot").style(height=750)

    with gr.Row():
        with gr.Column(scale=0.65):
            txt = gr.Textbox(
                show_label=False,
                placeholder="Enter text and press enter, or upload an image",
            ).style(container=False)
        with gr.Column(scale=0.35, min_width=0):
            url = gr.Textbox(
                show_label=False,
                placeholder="Enter url api endpoint",
            ).style(container=False)

    txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
        bot, chatbot, chatbot
    )
    url.submit(add_url, [chatbot, url], [chatbot, url]).then(
        bot, chatbot, chatbot
    )

if __name__ == "__main__":
    demo.launch()