Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -58,13 +58,12 @@ def respond(
|
|
58 |
except Exception as e:
|
59 |
yield f"An error occurred: {str(e)}"
|
60 |
|
61 |
-
# Define the UI layout with
|
62 |
with gr.Blocks() as demo:
|
63 |
gr.Markdown("# 🧠 AI Chatbot Interface")
|
64 |
gr.Markdown("### Customize your AI Chatbot's behavior and responses.")
|
65 |
|
66 |
with gr.Row():
|
67 |
-
chatbot = gr.Chatbot()
|
68 |
with gr.Column():
|
69 |
system_message = gr.Textbox(
|
70 |
value="You are a helpful assistant knowledgeable in various topics. Provide clear, concise, and friendly responses.",
|
@@ -76,14 +75,43 @@ with gr.Blocks() as demo:
|
|
76 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
77 |
|
78 |
with gr.Row():
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
# Update the chatbot with the new message and response
|
83 |
submit_btn.click(respond,
|
84 |
inputs=[message, chatbot, system_message, max_tokens, temperature, top_p],
|
85 |
outputs=[chatbot],
|
86 |
show_progress=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
# Launch the Gradio interface
|
89 |
if __name__ == "__main__":
|
|
|
58 |
except Exception as e:
|
59 |
yield f"An error occurred: {str(e)}"
|
60 |
|
61 |
+
# Define the UI layout with improved structure
|
62 |
with gr.Blocks() as demo:
|
63 |
gr.Markdown("# 🧠 AI Chatbot Interface")
|
64 |
gr.Markdown("### Customize your AI Chatbot's behavior and responses.")
|
65 |
|
66 |
with gr.Row():
|
|
|
67 |
with gr.Column():
|
68 |
system_message = gr.Textbox(
|
69 |
value="You are a helpful assistant knowledgeable in various topics. Provide clear, concise, and friendly responses.",
|
|
|
75 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
76 |
|
77 |
with gr.Row():
|
78 |
+
chatbot = gr.Chatbot()
|
79 |
+
|
80 |
+
with gr.Row():
|
81 |
+
with gr.Column():
|
82 |
+
sample_prompt = gr.Dropdown(
|
83 |
+
choices=[
|
84 |
+
"Can you explain the theory of relativity?",
|
85 |
+
"What are some tips for improving productivity at work?",
|
86 |
+
"Tell me a fun fact about space.",
|
87 |
+
"How can I cook a perfect omelette?",
|
88 |
+
"What's the latest news in technology?"
|
89 |
+
],
|
90 |
+
label="Sample Prompts",
|
91 |
+
value="Can you explain the theory of relativity?",
|
92 |
+
type="value"
|
93 |
+
)
|
94 |
+
message = gr.Textbox(label="Your message:", lines=1)
|
95 |
+
submit_btn = gr.Button("Send")
|
96 |
+
clear_btn = gr.Button("Clear Chat")
|
97 |
+
|
98 |
+
# Handle sample prompt selection
|
99 |
+
def update_message(prompt):
|
100 |
+
return prompt
|
101 |
+
|
102 |
+
sample_prompt.change(fn=update_message, inputs=sample_prompt, outputs=message)
|
103 |
|
104 |
# Update the chatbot with the new message and response
|
105 |
submit_btn.click(respond,
|
106 |
inputs=[message, chatbot, system_message, max_tokens, temperature, top_p],
|
107 |
outputs=[chatbot],
|
108 |
show_progress=True)
|
109 |
+
|
110 |
+
# Clear the chat history
|
111 |
+
def clear_chat():
|
112 |
+
return []
|
113 |
+
|
114 |
+
clear_btn.click(fn=clear_chat, inputs=None, outputs=chatbot)
|
115 |
|
116 |
# Launch the Gradio interface
|
117 |
if __name__ == "__main__":
|