File size: 1,796 Bytes
8e66315
 
 
 
 
 
f6d82ae
1db6389
f6d82ae
1db6389
 
 
8e66315
 
 
 
 
 
 
 
 
1db6389
8e66315
 
1db6389
f6d82ae
 
 
 
 
1db6389
 
 
 
 
 
 
2b7564f
a4b9f57
 
1db6389
 
 
 
 
 
 
 
 
f6d82ae
 
 
2f18584
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
# Imports
import gradio as gr
from helper_functions import *

with gr.Blocks() as app:
    gr.Markdown('# FundedNext Customer Service Chatbot')
    # Message Archived, Message Current, User Message, Bot Message
    session_data = gr.State([
        [{"role": "system", "content": pre_text}],[],[],[]
    ])


    with gr.Tab("Chat"):
        with gr.Row():
            with gr.Column():
                msg = gr.Textbox()
                with gr.Row():
                    submit = gr.Button("Submit")
                    clear = gr.Button("Clear")
            with gr.Column():
                chatbot = gr.Chatbot()
            
    with gr.Tab("Prompt"):
        context = gr.Textbox()
        submit_p = gr.Button("Check Prompt")
    
    with gr.Tab("Download"):
        file = gr.File(interactive = False)
        file_download_btn = gr.Button("Downlaod Chat History")

    # Tab Chat
    msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, [chatbot, session_data], [chatbot, session_data]
    ).then(
        fn = reset_memory, inputs = session_data, outputs = session_data
    )
    submit.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, [chatbot, session_data], [chatbot, session_data]
    ).then(
        fn = reset_memory, inputs = session_data, outputs = session_data
    )
    clear.click(
        fn = clear_data, 
        inputs = session_data, 
        outputs = [chatbot, session_data],
        queue = False
    )
    # Tab Prompt
    submit_p.click(get_context_gr, session_data, context, queue=False)
    # Tab Download
    file_download_btn.click(fn = download_file, inputs = session_data, outputs = file, queue = False)
# app.launch(debug=True)
app.launch(auth=(os.getenv("id"), os.getenv("password")), show_api=False)