Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -35,7 +35,7 @@ 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,
|
39 |
|
40 |
# Gradio Interface with enhanced styling
|
41 |
chat_interface = gr.Blocks(css="""
|
@@ -103,39 +103,36 @@ with chat_interface:
|
|
103 |
with gr.Row():
|
104 |
chatbot_output = gr.Chatbot(label="Chat History", type="messages")
|
105 |
with gr.Row():
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
">Copy Response</button>
|
119 |
<script>
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
navigator.clipboard.writeText(lastResponse)
|
125 |
-
.then(() => alert('Copied to clipboard!'))
|
126 |
-
.catch(() => alert('Failed to copy!'));
|
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 |
-
|
137 |
inputs=[user_input, category_dropdown, chatbot_output],
|
138 |
outputs=[chatbot_output, chatbot_output]
|
139 |
)
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
chat_interface.launch()
|
|
|
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, bot_response
|
39 |
|
40 |
# Gradio Interface with enhanced styling
|
41 |
chat_interface = gr.Blocks(css="""
|
|
|
103 |
with gr.Row():
|
104 |
chatbot_output = gr.Chatbot(label="Chat History", type="messages")
|
105 |
with gr.Row():
|
106 |
+
copy_button = gr.Button("Copy Response")
|
107 |
+
|
108 |
+
# Add functionality to handle interactions
|
109 |
+
def handle_chat(user_input, category, history):
|
110 |
+
if not user_input.strip():
|
111 |
+
return history, history
|
112 |
+
updated_history, bot_response = chatbot(user_input, category, history)
|
113 |
+
return updated_history, updated_history
|
114 |
+
|
115 |
+
def handle_copy(last_bot_response):
|
116 |
+
# Copy the last bot response to clipboard using the JavaScript in Gradio.
|
117 |
+
return gr.HTML(f"""
|
|
|
118 |
<script>
|
119 |
+
const copyText = '{last_bot_response}';
|
120 |
+
navigator.clipboard.writeText(copyText)
|
121 |
+
.then(() => alert('Copied to clipboard!'))
|
122 |
+
.catch(() => alert('Failed to copy!'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
</script>
|
124 |
""")
|
125 |
|
|
|
126 |
send_button.click(
|
127 |
+
handle_chat,
|
128 |
inputs=[user_input, category_dropdown, chatbot_output],
|
129 |
outputs=[chatbot_output, chatbot_output]
|
130 |
)
|
131 |
|
132 |
+
copy_button.click(
|
133 |
+
handle_copy,
|
134 |
+
inputs=[chatbot_output],
|
135 |
+
outputs=[]
|
136 |
+
)
|
137 |
+
|
138 |
chat_interface.launch()
|