File size: 1,688 Bytes
c5e443c
4bfc35b
c5e443c
 
 
7d415ff
c5e443c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f6e23d
 
4bfc35b
 
c5e443c
7d415ff
c5e443c
7d415ff
c5e443c
 
 
 
 
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
import gradio as gr
from styles import get_chat_interface_style, get_textbox_style, get_chatbox_style
import random
import time

def respond(message, chat_history, chat_history_slider):
    user_input = message.lower()

    # Topic-based responses
    if "technology" in user_input:
        bot_message = "Sure, let's talk about technology. What specific aspect are you interested in?"

    elif "science" in user_input:
        bot_message = "Science is fascinating! What scientific topic would you like to discuss?"

    elif "healthcare" in user_input:
        bot_message = "Healthcare is crucial. How can I assist you in the healthcare domain?"

    elif "education" in user_input:
        bot_message = "Education is important. What educational topic are you curious about?"

    elif "sports" in user_input:
        bot_message = "Sports are exciting! What sport or team are you a fan of?"

    else:
        bot_message = "Welcome! I'm Glo AI. How can I assist you today?"

    chat_history.append(bot_message)
    time.sleep(2)  # Simulating a brief delay for a more natural conversation
    return "", chat_history[-chat_history_slider.value:]

def launch_chat_app():
    with gr.Blocks() as demo:
        chat_interface_style = get_chat_interface_style()

        chatbot = gr.Chatbot(style=get_chatbox_style())
        msg = gr.Textbox("Write your input here", style=get_textbox_style())
        submit_button = gr.Button("Submit")
        chat_history_slider = gr.Slider(minimum=1, maximum=10, value=5, label="Chat History Length")

        submit_button.click(respond, [msg, chatbot, chat_history_slider])

    demo.launch()

if __name__ == "__main__":
    launch_chat_app()