Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,8 @@ def get_groq_response(message, category):
|
|
33 |
# Chatbot function
|
34 |
def chatbot(user_input, category, history=[]):
|
35 |
bot_response = get_groq_response(user_input, category)
|
36 |
-
history.append(
|
|
|
37 |
return history, history
|
38 |
|
39 |
# Gradio Interface with enhanced styling
|
@@ -100,20 +101,23 @@ with chat_interface:
|
|
100 |
with gr.Row():
|
101 |
send_button = gr.Button("Send")
|
102 |
with gr.Row():
|
103 |
-
chatbot_output = gr.Chatbot(label="Chat History")
|
104 |
with gr.Row():
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
117 |
const responses = document.querySelectorAll('.bot-message');
|
118 |
if (responses.length > 0) {
|
119 |
const lastResponse = responses[responses.length - 1].innerText;
|
@@ -123,16 +127,15 @@ with chat_interface:
|
|
123 |
} else {
|
124 |
alert('No bot response to copy!');
|
125 |
}
|
126 |
-
}
|
127 |
-
|
|
|
128 |
|
|
|
129 |
send_button.click(
|
130 |
-
|
131 |
inputs=[user_input, category_dropdown, chatbot_output],
|
132 |
outputs=[chatbot_output, chatbot_output]
|
133 |
)
|
134 |
|
135 |
-
# Attach the copy button functionality
|
136 |
-
copy_button.click(None, _js=copy_js)
|
137 |
-
|
138 |
chat_interface.launch()
|
|
|
33 |
# Chatbot function
|
34 |
def chatbot(user_input, category, history=[]):
|
35 |
bot_response = get_groq_response(user_input, category)
|
36 |
+
history.append({"role": "user", "content": user_input})
|
37 |
+
history.append({"role": "assistant", "content": bot_response})
|
38 |
return history, history
|
39 |
|
40 |
# Gradio Interface with enhanced styling
|
|
|
101 |
with gr.Row():
|
102 |
send_button = gr.Button("Send")
|
103 |
with gr.Row():
|
104 |
+
chatbot_output = gr.Chatbot(label="Chat History", type="messages")
|
105 |
with gr.Row():
|
106 |
+
# Custom HTML button
|
107 |
+
gr.HTML("""
|
108 |
+
<button id="copy-btn" style="
|
109 |
+
background: linear-gradient(90deg, #f9f9f9, #e6e6e6);
|
110 |
+
color: #555;
|
111 |
+
padding: 0.8rem 1.5rem;
|
112 |
+
font-size: 1rem;
|
113 |
+
font-weight: bold;
|
114 |
+
border-radius: 20px;
|
115 |
+
border: none;
|
116 |
+
cursor: pointer;
|
117 |
+
transition: transform 0.2s ease, background 0.2s ease;
|
118 |
+
">Copy Response</button>
|
119 |
+
<script>
|
120 |
+
document.getElementById('copy-btn').addEventListener('click', () => {
|
121 |
const responses = document.querySelectorAll('.bot-message');
|
122 |
if (responses.length > 0) {
|
123 |
const lastResponse = responses[responses.length - 1].innerText;
|
|
|
127 |
} else {
|
128 |
alert('No bot response to copy!');
|
129 |
}
|
130 |
+
});
|
131 |
+
</script>
|
132 |
+
""")
|
133 |
|
134 |
+
# Add functionality to handle interactions
|
135 |
send_button.click(
|
136 |
+
chatbot,
|
137 |
inputs=[user_input, category_dropdown, chatbot_output],
|
138 |
outputs=[chatbot_output, chatbot_output]
|
139 |
)
|
140 |
|
|
|
|
|
|
|
141 |
chat_interface.launch()
|