File size: 1,764 Bytes
439340a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
import os
import time

from utils import make_invisible, make_visible
from backend_functions import get_answer_text

from dotenv import load_dotenv
load_dotenv()



with gr.Blocks() as main_app:
    with gr.Tab('Chatbot'):
        user_id = gr.State('')  # id used to find the chat into the database

        chat = gr.Chatbot(label="Chatbot Crunchyroll")

        messages = gr.State([])

        with gr.Row():
            text = gr.Textbox(label='Write your question')

        with gr.Row():
            with gr.Column():
                button_text = gr.Button(value='Submit text')
            with gr.Column():
                clear_button = gr.ClearButton([chat, messages])



    # with gr.Tab('Ventana Pruebas'):
    #     with gr.Row():
    #         with gr.Column():
    #             button_show = gr.Button(value="Mostrar texto")
    #         with gr.Column():
    #             button_hidden = gr.Button(value="Ocultar texto")
        
    #     with gr.Row(visible=False) as first_row:
    #         text = gr.Textbox(value="Hola mundo")


    # Actions
        
    # button_show.click(
    #     fn=make_visible,
    #     inputs=None,
    #     outputs=first_row
    # )
    
    # button_hidden.click(
    #     fn=make_invisible,
    #     inputs=None,
    #     outputs=first_row
    # )

    text.submit(
        fn=get_answer_text,
        inputs=[text, chat, messages],
        outputs=[chat]
    ).then(
        lambda: None, None, [text]
    )

    button_text.click(
        fn=get_answer_text,
        inputs=[text, chat, messages],
        outputs=[chat]
    ).then(
        lambda: None, None, [text]
    )



main_app.launch(debug=True, auth=(os.environ.get('SPACE_USERNAME'), os.environ.get('SPACE_PASSWORD')))