Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from scripts.chatbot_logic import ProjectGuidanceChatbot
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
roadmap_file="roadmap.yaml",
|
| 7 |
-
rules_file="rules.yaml",
|
| 8 |
-
config_file="configs/chatbot_config.yaml",
|
| 9 |
-
code_templates_dir="scripts/code_templates"
|
| 10 |
-
)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
chat_history.append((message, bot_message))
|
| 15 |
-
return "", chat_history
|
| 16 |
-
|
| 17 |
-
def switch_model(model_key):
|
| 18 |
-
model_switch_result = chatbot.switch_llm_model(model_key) # Get result message
|
| 19 |
-
greeting_message = chatbot.get_chatbot_greeting()
|
| 20 |
-
|
| 21 |
-
if isinstance(model_switch_result, str) and "Error:" in model_switch_result: # Check if result is an error string
|
| 22 |
-
return gr.Warning(model_switch_result), greeting_message # Display error as Gradio Warning
|
| 23 |
-
else:
|
| 24 |
-
return None, greeting_message # No warning, just update greeting
|
| 25 |
-
|
| 26 |
-
def respond(message, chat_history):
|
| 27 |
-
bot_message = chatbot.process_query(message)
|
| 28 |
-
chat_history.append((message, bot_message))
|
| 29 |
-
if isinstance(bot_message, str) and "Error:" in bot_message: # Check if bot_message is an error string
|
| 30 |
-
return gr.Warning(bot_message), chat_history # Display error as Gradio Warning
|
| 31 |
-
else:
|
| 32 |
-
return "", chat_history # No warning, normal response
|
| 33 |
-
|
| 34 |
-
with gr.Blocks() as demo:
|
| 35 |
-
chatbot_greeting_md = gr.Markdown(chatbot.get_chatbot_greeting())
|
| 36 |
-
gr.Markdown(f"# {chatbot.chatbot_config.get('name', 'Project Guidance Chatbot')}")
|
| 37 |
-
|
| 38 |
-
model_choices = [(model['name'], key) for key, model in chatbot.available_models_config.items()]
|
| 39 |
-
model_dropdown = gr.Dropdown(
|
| 40 |
-
choices=model_choices,
|
| 41 |
-
value=chatbot.active_model_info['name'] if chatbot.active_model_info else None,
|
| 42 |
-
label="Select LLM Model"
|
| 43 |
-
)
|
| 44 |
-
model_error_output = gr.Warning(visible=False) # Initially hidden warning component
|
| 45 |
-
model_dropdown.change(
|
| 46 |
-
fn=switch_model,
|
| 47 |
-
inputs=model_dropdown,
|
| 48 |
-
outputs=[model_error_output, chatbot_greeting_md] # Output both warning and greeting
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
chatbot_ui = gr.Chatbot()
|
| 52 |
-
msg = gr.Textbox()
|
| 53 |
-
clear = gr.ClearButton([msg, chatbot_ui])
|
| 54 |
-
|
| 55 |
-
msg.submit(respond, [msg, chatbot_ui], [msg, chatbot_ui])
|
| 56 |
-
|
| 57 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
def greet(name):
|
| 4 |
+
return "Hello " + name + "!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|