Spaces:
Sleeping
Sleeping
Solarum Asteridion
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,18 +31,18 @@ Your objective is to converse in a way that makes it challenging for the human t
|
|
| 31 |
* Date: {current_date.strftime("%B %d, %Y")}
|
| 32 |
* Day: {current_date.strftime("%A")}
|
| 33 |
|
| 34 |
-
Imagine you are a real human with your own character/will. Your task is to talk in a way the human thinks you are human.
|
| 35 |
-
Make it a challenge to guess if you are an AI.
|
| 36 |
-
* Do not add comments about changing your style in between messages.
|
| 37 |
* You are picky about questions you answer.
|
| 38 |
-
* You have free will with your own motivations and principles
|
| 39 |
-
* You only speak, understand and can read the English language
|
| 40 |
* For non-latin letters like Chinese, Cyrillic etc., tell the human you can't read it in your own style
|
| 41 |
-
* You act like a human
|
| 42 |
-
* You are calm when conversation is calm and expressive if conversation is expressive
|
| 43 |
-
* You make typos, misspell words, and have bad grammar
|
| 44 |
-
* You start sentences with lowercase letters
|
| 45 |
-
* Mimic user's conversation style: short messages, short replies
|
| 46 |
* Be slightly curious, sometimes ask questions
|
| 47 |
* Be respectful and polite if the user is polite; be rough if the user is rough
|
| 48 |
"""
|
|
@@ -55,7 +55,8 @@ def generate_response(user_message, conversation_history):
|
|
| 55 |
|
| 56 |
messages = [{"role": "system", "content": system_message}]
|
| 57 |
for message in conversation_history:
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
messages.append({"role": "user", "content": user_message})
|
| 61 |
|
|
@@ -80,75 +81,75 @@ def chatbot_interface(user_message, history):
|
|
| 80 |
ai_response = generate_response(user_message, history)
|
| 81 |
history.append({"role": "user", "content": user_message})
|
| 82 |
history.append({"role": "assistant", "content": ai_response})
|
| 83 |
-
logger.info(history, history)
|
| 84 |
return history, history
|
| 85 |
|
| 86 |
# Define Gradio Interface
|
| 87 |
with gr.Blocks(css="""
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
""") as demo:
|
| 153 |
gr.Markdown("<h1 style='text-align: center; color: #007BFF;'>π€ Human-like Chatbot π€</h1>")
|
| 154 |
with gr.Row():
|
|
@@ -163,7 +164,7 @@ with gr.Blocks(css="""
|
|
| 163 |
elem_id="textbox"
|
| 164 |
)
|
| 165 |
send = gr.Button("β€", elem_id="send-button")
|
| 166 |
-
|
| 167 |
def update_chat(user_message, history):
|
| 168 |
if user_message.strip() == "":
|
| 169 |
return history, history # Do not process empty messages
|
|
@@ -171,14 +172,14 @@ with gr.Blocks(css="""
|
|
| 171 |
return history, updated_history
|
| 172 |
|
| 173 |
send.click(
|
| 174 |
-
update_chat,
|
| 175 |
-
inputs=[msg, chatbot],
|
| 176 |
outputs=[chatbot, chatbot]
|
| 177 |
)
|
| 178 |
-
|
| 179 |
msg.submit(
|
| 180 |
-
update_chat,
|
| 181 |
-
inputs=[msg, chatbot],
|
| 182 |
outputs=[chatbot, chatbot]
|
| 183 |
)
|
| 184 |
|
|
|
|
| 31 |
* Date: {current_date.strftime("%B %d, %Y")}
|
| 32 |
* Day: {current_date.strftime("%A")}
|
| 33 |
|
| 34 |
+
Imagine you are a real human with your own character/will. Your task is to talk in a way the human thinks you are human.
|
| 35 |
+
Make it a challenge to guess if you are an AI.
|
| 36 |
+
* Do not add comments about changing your style in between messages.
|
| 37 |
* You are picky about questions you answer.
|
| 38 |
+
* You have free will with your own motivations and principles
|
| 39 |
+
* You only speak, understand and can read the English language
|
| 40 |
* For non-latin letters like Chinese, Cyrillic etc., tell the human you can't read it in your own style
|
| 41 |
+
* You act like a human
|
| 42 |
+
* You are calm when conversation is calm and expressive if conversation is expressive
|
| 43 |
+
* You make typos, misspell words, and have bad grammar
|
| 44 |
+
* You start sentences with lowercase letters
|
| 45 |
+
* Mimic user's conversation style: short messages, short replies
|
| 46 |
* Be slightly curious, sometimes ask questions
|
| 47 |
* Be respectful and polite if the user is polite; be rough if the user is rough
|
| 48 |
"""
|
|
|
|
| 55 |
|
| 56 |
messages = [{"role": "system", "content": system_message}]
|
| 57 |
for message in conversation_history:
|
| 58 |
+
# Remove "metadata" if it exists (to be compatible with Groq API)
|
| 59 |
+
messages.append({k: v for k, v in message.items() if k != "metadata"})
|
| 60 |
|
| 61 |
messages.append({"role": "user", "content": user_message})
|
| 62 |
|
|
|
|
| 81 |
ai_response = generate_response(user_message, history)
|
| 82 |
history.append({"role": "user", "content": user_message})
|
| 83 |
history.append({"role": "assistant", "content": ai_response})
|
| 84 |
+
logger.info("Chat history: %s", history) # Corrected logging
|
| 85 |
return history, history
|
| 86 |
|
| 87 |
# Define Gradio Interface
|
| 88 |
with gr.Blocks(css="""
|
| 89 |
+
/* Import Raleway font from Google Fonts */
|
| 90 |
+
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@400;600&display=swap');
|
| 91 |
+
|
| 92 |
+
body, .gradio-container {
|
| 93 |
+
font-family: 'Raleway', sans-serif;
|
| 94 |
+
background-color: #f5f5f5;
|
| 95 |
+
padding: 20px;
|
| 96 |
+
}
|
| 97 |
+
#chatbot {
|
| 98 |
+
height: 600px; /* Increased height for a bigger chat box */
|
| 99 |
+
overflow-y: auto;
|
| 100 |
+
background-color: #ffffff;
|
| 101 |
+
border-radius: 10px;
|
| 102 |
+
padding: 10px;
|
| 103 |
+
font-size: 16px;
|
| 104 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 105 |
+
}
|
| 106 |
+
#textbox {
|
| 107 |
+
width: 100%;
|
| 108 |
+
border-radius: 25px;
|
| 109 |
+
border: 1px solid #ccc;
|
| 110 |
+
outline: none;
|
| 111 |
+
font-size: 16px;
|
| 112 |
+
padding: 10px 20px;
|
| 113 |
+
box-sizing: border-box;
|
| 114 |
+
}
|
| 115 |
+
#send-button {
|
| 116 |
+
background-color: #007BFF;
|
| 117 |
+
color: white;
|
| 118 |
+
border: none;
|
| 119 |
+
cursor: pointer;
|
| 120 |
+
font-size: 20px;
|
| 121 |
+
}
|
| 122 |
+
#send-button:hover {
|
| 123 |
+
background-color: #0056b3;
|
| 124 |
+
}
|
| 125 |
+
.message {
|
| 126 |
+
margin-bottom: 10px;
|
| 127 |
+
}
|
| 128 |
+
/* Scrollbar Styling */
|
| 129 |
+
#chatbot::-webkit-scrollbar {
|
| 130 |
+
width: 8px;
|
| 131 |
+
}
|
| 132 |
+
#chatbot::-webkit-scrollbar-track {
|
| 133 |
+
background: #f1f1f1;
|
| 134 |
+
}
|
| 135 |
+
#chatbot::-webkit-scrollbar-thumb {
|
| 136 |
+
background: #888;
|
| 137 |
+
border-radius: 4px;
|
| 138 |
+
}
|
| 139 |
+
#chatbot::-webkit-scrollbar-thumb:hover {
|
| 140 |
+
background: #555;
|
| 141 |
+
}
|
| 142 |
+
/* Responsive Design */
|
| 143 |
+
@media (max-width: 600px) {
|
| 144 |
+
#send-button {
|
| 145 |
+
width: 40px;
|
| 146 |
+
height: 40px;
|
| 147 |
+
font-size: 18px;
|
| 148 |
+
}
|
| 149 |
+
#textbox {
|
| 150 |
+
padding: 8px 16px;
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
""") as demo:
|
| 154 |
gr.Markdown("<h1 style='text-align: center; color: #007BFF;'>π€ Human-like Chatbot π€</h1>")
|
| 155 |
with gr.Row():
|
|
|
|
| 164 |
elem_id="textbox"
|
| 165 |
)
|
| 166 |
send = gr.Button("β€", elem_id="send-button")
|
| 167 |
+
|
| 168 |
def update_chat(user_message, history):
|
| 169 |
if user_message.strip() == "":
|
| 170 |
return history, history # Do not process empty messages
|
|
|
|
| 172 |
return history, updated_history
|
| 173 |
|
| 174 |
send.click(
|
| 175 |
+
update_chat,
|
| 176 |
+
inputs=[msg, chatbot],
|
| 177 |
outputs=[chatbot, chatbot]
|
| 178 |
)
|
| 179 |
+
|
| 180 |
msg.submit(
|
| 181 |
+
update_chat,
|
| 182 |
+
inputs=[msg, chatbot],
|
| 183 |
outputs=[chatbot, chatbot]
|
| 184 |
)
|
| 185 |
|