| | import gradio as gr |
| | from scripts.chatbot_logic import ProjectGuidanceChatbot |
| |
|
| | |
| | chatbot = ProjectGuidanceChatbot( |
| | roadmap_file="roadmap.yaml", |
| | rules_file="rules.yaml", |
| | config_file="configs/chatbot_config.yaml", |
| | code_templates_dir="scripts/code_templates" |
| | ) |
| |
|
| | def respond(message, chat_history): |
| | bot_message = chatbot.process_query(message) |
| | chat_history.append((message, bot_message)) |
| | return "", chat_history |
| |
|
| | def switch_model(model_key): |
| | model_switch_result = chatbot.switch_llm_model(model_key) |
| | greeting_message = chatbot.get_chatbot_greeting() |
| |
|
| | if isinstance(model_switch_result, str) and "Error:" in model_switch_result: |
| | return gr.Warning(model_switch_result), greeting_message |
| | else: |
| | return None, greeting_message |
| |
|
| | with gr.Blocks() as demo: |
| | chatbot_greeting_md = gr.Markdown(chatbot.get_chatbot_greeting()) |
| | gr.Markdown(f"# {chatbot.chatbot_config.get('name', 'Project Guidance Chatbot')}") |
| |
|
| | model_choices = [(model['name'], key) for key, model in chatbot.available_models_config.items()] |
| | model_dropdown = gr.Dropdown( |
| | choices=model_choices, |
| | value=chatbot.active_model_info['name'] if chatbot.active_model_info else None, |
| | label="Select LLM Model" |
| | ) |
| | model_error_output = gr.Warning(visible=False) |
| | model_dropdown.change( |
| | fn=switch_model, |
| | inputs=model_dropdown, |
| | outputs=[model_error_output, chatbot_greeting_md] |
| | ) |
| |
|
| | chatbot_ui = gr.Chatbot() |
| | msg = gr.Textbox() |
| | clear = gr.ClearButton([msg, chatbot_ui]) |
| |
|
| | msg.submit(respond, [msg, chatbot_ui], [msg, chatbot_ui]) |
| |
|
| | demo.launch() |