File size: 3,281 Bytes
c493259
 
6848c8b
c493259
 
 
ae3c993
 
 
6848c8b
c493259
 
 
 
 
 
6848c8b
 
 
 
 
 
c493259
6848c8b
 
 
 
 
 
 
 
 
 
 
 
 
 
c493259
6848c8b
 
57cde09
6848c8b
 
 
 
 
 
 
 
 
 
 
 
 
57cde09
 
6848c8b
 
 
 
57cde09
 
6848c8b
c34bad6
c493259
6848c8b
 
 
 
 
c493259
6848c8b
 
 
 
 
 
 
340b532
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
76
77
78
79
80
#%%
import gradio as gr
from chat_logic.chat_stream import chatbot_interface, feedback_positive, feedback_negative, handle_user_input
from ui.custom_css import custom_css

def interface_init():
    """
    Initialize the Gradio interface for the Repair Assistant chatbot.
    """

    logo_path = "./images/logo.png"

    # Gradio UI
    with gr.Blocks() as app:
        gr.HTML(custom_css())  # Insert custom CSS

        # Create a row for the layout
        with gr.Row():
            # Left container for the logo, input, and buttons
            with gr.Column(scale=1, elem_id="gradio-left-container"):
                # Logo
                gr.Image(logo_path, elem_id="logo", show_label=False, show_fullscreen_button=False)

                response_type = gr.Radio(
                    ["Simple Language", "Technical", "Homer Simpson Language", "Sarcasm"],
                    label="Answer Style"
                )
                
                # Feedback section (thumbs up and thumbs down buttons, and markdown)
                gr.Markdown("🛠️ **Did the repair work?**")
                with gr.Row(elem_classes="feedback-buttons"):
                    thumbs_up = gr.Button("👍 Yes")
                    thumbs_down = gr.Button("👎 No")
                
            # Right container for the chat output and feedback buttons
            with gr.Column(scale=2, elem_id="gradio-right-container"):
                # Chat history output

                # chat_history = gr.State([])  # For maintaining the chat state
                conversation_state = gr.State("interactive_diagnosis") # For awaiting the users response if support ticket is needed
                vector_db = gr.State([]) # For awaiting the users response if support ticket is needed
                chatbot = gr.Chatbot(elem_id="chat-container")
                
                # Input components
                user_input = gr.Textbox(
                    label="Pick an answer style and let the Repair Assistant help you!",
                    placeholder="Your input here",

                    elem_classes="input-textbox"
                )
                submit_btn = gr.Button("Submit", elem_classes="submit-button")

                submit_btn.click(
                    fn=handle_user_input,
                    inputs=[user_input, chatbot, conversation_state, response_type, vector_db],
                    outputs=[chatbot, user_input, conversation_state, vector_db]
                )

                user_input.submit(
                    fn=handle_user_input,
                    inputs=[user_input, chatbot, conversation_state, response_type, vector_db],
                    outputs=[chatbot, user_input, conversation_state, vector_db]
                )
                gr.Markdown("🚫 **Verify Information and use at your own risk!**")
        # Connect thumbs up to success message (stops chat)
        thumbs_up.click(
            fn=feedback_positive,
            inputs=[chatbot],
            outputs=[chatbot, user_input, conversation_state]
        )

        # Connect thumbs down
        thumbs_down.click(
            fn=feedback_negative,
            inputs=[chatbot],
            outputs=[chatbot, conversation_state]
        )
    
    app.queue().launch()