Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,8 +52,8 @@ body {
|
|
| 52 |
100% { background-position: 0% 50%; }
|
| 53 |
}
|
| 54 |
button {
|
| 55 |
-
background: linear-gradient(90deg, #
|
| 56 |
-
color:
|
| 57 |
padding: 0.8rem 1.5rem;
|
| 58 |
font-size: 1rem;
|
| 59 |
font-weight: bold;
|
|
@@ -63,8 +63,8 @@ button {
|
|
| 63 |
transition: transform 0.2s ease, background 0.2s ease;
|
| 64 |
}
|
| 65 |
button:hover {
|
| 66 |
-
background: linear-gradient(90deg, #
|
| 67 |
-
transform: scale(1.
|
| 68 |
}
|
| 69 |
header {
|
| 70 |
text-align: center;
|
|
@@ -101,8 +101,9 @@ with chat_interface:
|
|
| 101 |
send_button = gr.Button("Send")
|
| 102 |
with gr.Row():
|
| 103 |
chatbot_output = gr.Chatbot(label="Chat History")
|
|
|
|
| 104 |
copy_button = gr.Button("Copy Response")
|
| 105 |
-
|
| 106 |
# Add functionality to handle interactions
|
| 107 |
def handle_chat(user_input, category, history):
|
| 108 |
if not user_input.strip():
|
|
@@ -110,23 +111,28 @@ with chat_interface:
|
|
| 110 |
updated_history, _ = chatbot(user_input, category, history)
|
| 111 |
return updated_history, updated_history
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
send_button.click(
|
| 114 |
handle_chat,
|
| 115 |
inputs=[user_input, category_dropdown, chatbot_output],
|
| 116 |
outputs=[chatbot_output, chatbot_output]
|
| 117 |
)
|
| 118 |
|
| 119 |
-
#
|
| 120 |
-
|
| 121 |
-
if history:
|
| 122 |
-
return history[-1][1] # Returns the last bot response
|
| 123 |
-
return "No response to copy."
|
| 124 |
-
|
| 125 |
-
copy_button.click(
|
| 126 |
-
copy_last_response,
|
| 127 |
-
inputs=[chatbot_output],
|
| 128 |
-
outputs=[]
|
| 129 |
-
)
|
| 130 |
|
| 131 |
chat_interface.launch()
|
| 132 |
-
|
|
|
|
| 52 |
100% { background-position: 0% 50%; }
|
| 53 |
}
|
| 54 |
button {
|
| 55 |
+
background: linear-gradient(90deg, #a1c4fd, #c2e9fb);
|
| 56 |
+
color: #333;
|
| 57 |
padding: 0.8rem 1.5rem;
|
| 58 |
font-size: 1rem;
|
| 59 |
font-weight: bold;
|
|
|
|
| 63 |
transition: transform 0.2s ease, background 0.2s ease;
|
| 64 |
}
|
| 65 |
button:hover {
|
| 66 |
+
background: linear-gradient(90deg, #c2e9fb, #a1c4fd);
|
| 67 |
+
transform: scale(1.05);
|
| 68 |
}
|
| 69 |
header {
|
| 70 |
text-align: center;
|
|
|
|
| 101 |
send_button = gr.Button("Send")
|
| 102 |
with gr.Row():
|
| 103 |
chatbot_output = gr.Chatbot(label="Chat History")
|
| 104 |
+
with gr.Row():
|
| 105 |
copy_button = gr.Button("Copy Response")
|
| 106 |
+
|
| 107 |
# Add functionality to handle interactions
|
| 108 |
def handle_chat(user_input, category, history):
|
| 109 |
if not user_input.strip():
|
|
|
|
| 111 |
updated_history, _ = chatbot(user_input, category, history)
|
| 112 |
return updated_history, updated_history
|
| 113 |
|
| 114 |
+
# JavaScript for copying the last bot response
|
| 115 |
+
copy_js = """
|
| 116 |
+
function copyLastResponse() {
|
| 117 |
+
const responses = document.querySelectorAll('.bot-message');
|
| 118 |
+
if (responses.length > 0) {
|
| 119 |
+
const lastResponse = responses[responses.length - 1].innerText;
|
| 120 |
+
navigator.clipboard.writeText(lastResponse)
|
| 121 |
+
.then(() => alert('Copied to clipboard!'))
|
| 122 |
+
.catch(() => alert('Failed to copy!'));
|
| 123 |
+
} else {
|
| 124 |
+
alert('No bot response to copy!');
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
send_button.click(
|
| 130 |
handle_chat,
|
| 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()
|
|
|