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()