fix couple of bugs

This commit is contained in:
Mika Bomm 2025-01-08 11:23:41 +01:00
parent 7ea2129c93
commit f2aa98b712

8
app.py
View file

@ -27,12 +27,12 @@ def ask(text, model):
print("Formatted History: ", formatted_history)
return formatted_history, ""
def clear_history():
def clear_history(model):
global chat_history
chat_history = []
# Reset the conversation on the server side
client.chat.completions.create(
model="llama3.2",
model=model,
messages=[{"role": "system", "content": "Reset conversation"}]
)
return ""
@ -40,7 +40,7 @@ def clear_history():
with gr.Blocks() as server:
with gr.Tab("Chatbot LF6"):
model_dropdown = gr.Dropdown(label="Select Model", choices=get_models(), value="llama3.2")
model_dropdown = gr.Dropdown(label="Select Model", choices=get_models())
chatbox = gr.Textbox(label="Chat History", lines=10, interactive=False)
input_text = gr.Textbox(label="Input Text", placeholder="Enter your text here...")
submit_button = gr.Button("Submit")
@ -48,6 +48,6 @@ with gr.Blocks() as server:
submit_button.click(fn=lambda text, model: ask(text, model), inputs=[input_text, model_dropdown], outputs=[chatbox, input_text])
input_text.submit(fn=lambda text, model: ask(text, model), inputs=[input_text, model_dropdown], outputs=[chatbox, input_text]) # Submit on Enter key press
clear_button.click(fn=clear_history, inputs=None, outputs=chatbox)
clear_button.click(fn=clear_history, inputs=model_dropdown, outputs=chatbox)
server.launch()