Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
-
import pyperclip
|
4 |
|
5 |
# Set OpenAI API Key
|
6 |
openai.api_key = "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"
|
@@ -50,7 +49,7 @@ def chatbot(user_input, history=[]):
|
|
50 |
history.append((f"({topic}) You: {user_input}", f"Motivator Bot: {bot_response}"))
|
51 |
return history, saved_chats
|
52 |
|
53 |
-
#
|
54 |
def display_saved_chats():
|
55 |
display = ""
|
56 |
for category, chats in saved_chats.items():
|
@@ -60,7 +59,7 @@ def display_saved_chats():
|
|
60 |
display += "</div>"
|
61 |
return display.strip()
|
62 |
|
63 |
-
#
|
64 |
chat_interface = gr.Blocks(css="""
|
65 |
body {
|
66 |
font-family: 'Poppins', sans-serif;
|
@@ -140,38 +139,21 @@ button:hover {
|
|
140 |
transform: translateY(-3px);
|
141 |
box-shadow: 0px 4px 15px rgba(255, 127, 179, 0.5);
|
142 |
}
|
143 |
-
|
144 |
-
h1 {
|
145 |
-
color: #ff758c;
|
146 |
-
font-size: 3rem;
|
147 |
-
text-align: center;
|
148 |
-
animation: colorChange 3s infinite alternate;
|
149 |
-
}
|
150 |
-
|
151 |
-
@keyframes colorChange {
|
152 |
-
0% { color: #ff758c; }
|
153 |
-
25% { color: #ff7eb3; }
|
154 |
-
50% { color: #ff9a9e; }
|
155 |
-
75% { color: #ffb3d9; }
|
156 |
-
100% { color: #a1c4fd; }
|
157 |
-
}
|
158 |
""")
|
159 |
|
160 |
with chat_interface:
|
161 |
with gr.Row():
|
162 |
-
gr.Markdown("<h1 style='text-align:center;'>π
|
163 |
with gr.Row():
|
164 |
gr.Markdown("**Feeling stressed or unmotivated? Share your thoughts and let me help!**")
|
165 |
with gr.Row():
|
166 |
-
chatbot_output = gr.Chatbot(label="Motivator Bot"
|
167 |
with gr.Row():
|
168 |
user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
|
169 |
send_button = gr.Button("Send")
|
170 |
with gr.Row():
|
171 |
saved_chats_display = gr.HTML(label="Saved Chats", value=display_saved_chats())
|
172 |
refresh_button = gr.Button("Refresh Saved Chats")
|
173 |
-
copy_button = gr.Button("Copy Chat")
|
174 |
-
screenshot_button = gr.Button("Save Screenshot")
|
175 |
|
176 |
def handle_interaction(user_input, history):
|
177 |
if not user_input.strip():
|
@@ -179,18 +161,8 @@ with chat_interface:
|
|
179 |
updated_history, _ = chatbot(user_input, history)
|
180 |
return updated_history, display_saved_chats()
|
181 |
|
182 |
-
def copy_chat_to_clipboard():
|
183 |
-
chat_content = "\n".join([f"You: {user}\nBot: {bot}" for user, bot in saved_chats["General"]])
|
184 |
-
pyperclip.copy(chat_content) # Copies chat content to clipboard
|
185 |
-
return "Chat copied to clipboard!"
|
186 |
-
|
187 |
-
def save_screenshot():
|
188 |
-
return "Screenshot feature coming soon!" # Placeholder for future screenshot functionality
|
189 |
-
|
190 |
send_button.click(handle_interaction, inputs=[user_input, chatbot_output], outputs=[chatbot_output, saved_chats_display])
|
191 |
refresh_button.click(display_saved_chats, inputs=[], outputs=saved_chats_display)
|
192 |
-
copy_button.click(copy_chat_to_clipboard, inputs=[], outputs=[gr.Text(label="Status"), saved_chats_display])
|
193 |
-
screenshot_button.click(save_screenshot, inputs=[], outputs=[gr.Text(label="Status"), saved_chats_display])
|
194 |
|
195 |
if __name__ == "__main__":
|
196 |
chat_interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
|
|
3 |
|
4 |
# Set OpenAI API Key
|
5 |
openai.api_key = "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"
|
|
|
49 |
history.append((f"({topic}) You: {user_input}", f"Motivator Bot: {bot_response}"))
|
50 |
return history, saved_chats
|
51 |
|
52 |
+
# Function to display saved chats
|
53 |
def display_saved_chats():
|
54 |
display = ""
|
55 |
for category, chats in saved_chats.items():
|
|
|
59 |
display += "</div>"
|
60 |
return display.strip()
|
61 |
|
62 |
+
# Gradio Interface setup
|
63 |
chat_interface = gr.Blocks(css="""
|
64 |
body {
|
65 |
font-family: 'Poppins', sans-serif;
|
|
|
139 |
transform: translateY(-3px);
|
140 |
box-shadow: 0px 4px 15px rgba(255, 127, 179, 0.5);
|
141 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
""")
|
143 |
|
144 |
with chat_interface:
|
145 |
with gr.Row():
|
146 |
+
gr.Markdown("<h1 style='text-align:center;'>π Vibrant Motivational Chatbot</h1>")
|
147 |
with gr.Row():
|
148 |
gr.Markdown("**Feeling stressed or unmotivated? Share your thoughts and let me help!**")
|
149 |
with gr.Row():
|
150 |
+
chatbot_output = gr.Chatbot(label="Motivator Bot")
|
151 |
with gr.Row():
|
152 |
user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
|
153 |
send_button = gr.Button("Send")
|
154 |
with gr.Row():
|
155 |
saved_chats_display = gr.HTML(label="Saved Chats", value=display_saved_chats())
|
156 |
refresh_button = gr.Button("Refresh Saved Chats")
|
|
|
|
|
157 |
|
158 |
def handle_interaction(user_input, history):
|
159 |
if not user_input.strip():
|
|
|
161 |
updated_history, _ = chatbot(user_input, history)
|
162 |
return updated_history, display_saved_chats()
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
send_button.click(handle_interaction, inputs=[user_input, chatbot_output], outputs=[chatbot_output, saved_chats_display])
|
165 |
refresh_button.click(display_saved_chats, inputs=[], outputs=saved_chats_display)
|
|
|
|
|
166 |
|
167 |
if __name__ == "__main__":
|
168 |
chat_interface.launch()
|