Update app.py
Browse files
app.py
CHANGED
|
@@ -88,13 +88,13 @@ HEADERS = {
|
|
| 88 |
}
|
| 89 |
|
| 90 |
def query_deepseek(prompt):
|
| 91 |
-
"""Send a prompt to DeepSeek-R1 and get a clean response."""
|
| 92 |
payload = {
|
| 93 |
"inputs": prompt,
|
| 94 |
"parameters": {
|
| 95 |
-
"max_new_tokens": 80, #
|
| 96 |
-
"temperature": 0.5, #
|
| 97 |
-
"top_p": 0.85, #
|
| 98 |
"stop": ["\n", "User:", "Assistant:"] # Stop at natural breaks
|
| 99 |
}
|
| 100 |
}
|
|
@@ -104,7 +104,7 @@ def query_deepseek(prompt):
|
|
| 104 |
response.raise_for_status()
|
| 105 |
result = response.json()
|
| 106 |
generated_text = result[0]["generated_text"].strip()
|
| 107 |
-
# Remove the prompt if
|
| 108 |
if prompt in generated_text:
|
| 109 |
return generated_text.replace(prompt, "").strip()
|
| 110 |
return generated_text
|
|
@@ -115,25 +115,23 @@ def query_deepseek(prompt):
|
|
| 115 |
|
| 116 |
def chat_interface(user_input, history):
|
| 117 |
"""Handle chatbot interaction with Gradio."""
|
| 118 |
-
# Build a
|
| 119 |
if history:
|
| 120 |
-
prompt = "\n".join([f"U: {h[0]} | A: {h[1]}" for h in history]) + f"\nU: {user_input} | A: "
|
| 121 |
else:
|
| 122 |
-
prompt = f"U: {user_input} | A: "
|
| 123 |
|
| 124 |
-
# Get response and
|
| 125 |
response = query_deepseek(prompt)
|
|
|
|
| 126 |
|
| 127 |
-
#
|
| 128 |
-
response = response.replace("U: ", "").replace("| A: ", "").strip()
|
| 129 |
-
|
| 130 |
-
# Final deduplication: split into sentences and keep unique ones
|
| 131 |
sentences = response.split(". ")
|
| 132 |
unique_sentences = []
|
| 133 |
[unique_sentences.append(s) for s in sentences if s not in unique_sentences and s]
|
| 134 |
return ". ".join(unique_sentences).strip()
|
| 135 |
|
| 136 |
-
#
|
| 137 |
css = """
|
| 138 |
body {
|
| 139 |
background: #000000; /* Deep black background */
|
|
@@ -159,7 +157,6 @@ body {
|
|
| 159 |
color: #00ffcc;
|
| 160 |
}
|
| 161 |
|
| 162 |
-
/* Style the chat messages */
|
| 163 |
.chatbot-container .message {
|
| 164 |
margin: 10px 0;
|
| 165 |
padding: 8px;
|
|
@@ -182,25 +179,25 @@ input {
|
|
| 182 |
}
|
| 183 |
|
| 184 |
button#submit_btn {
|
| 185 |
-
background: #
|
| 186 |
color: #ffffff !important;
|
| 187 |
border: none !important;
|
| 188 |
padding: 10px 20px !important;
|
| 189 |
border-radius: 20px !important;
|
| 190 |
font-family: 'Courier New', monospace;
|
| 191 |
font-weight: bold;
|
| 192 |
-
box-shadow: 0 0 10px #
|
| 193 |
transition: all 0.3s ease;
|
| 194 |
}
|
| 195 |
|
| 196 |
button#submit_btn:hover {
|
| 197 |
-
background: #
|
| 198 |
-
box-shadow: 0 0 15px #
|
| 199 |
transform: scale(1.1); /* Slight grow effect */
|
| 200 |
}
|
| 201 |
|
| 202 |
.title {
|
| 203 |
-
color: #
|
| 204 |
font-size: 2em;
|
| 205 |
text-align: center;
|
| 206 |
text-transform: uppercase;
|
|
@@ -216,18 +213,18 @@ button#submit_btn:hover {
|
|
| 216 |
|
| 217 |
/* Glow animation for title */
|
| 218 |
@keyframes glow {
|
| 219 |
-
from { text-shadow: 0 0 5px #
|
| 220 |
-
to { text-shadow: 0 0 15px #
|
| 221 |
}
|
| 222 |
"""
|
| 223 |
|
| 224 |
-
# Create Gradio interface
|
| 225 |
interface = gr.ChatInterface(
|
| 226 |
fn=chat_interface,
|
| 227 |
title="LocoBot: Neural Nexus",
|
| 228 |
description="A quirky AI companion powered by DeepSeek-R1. Ask away!",
|
| 229 |
css=css,
|
| 230 |
-
submit_btn=gr.Button("
|
| 231 |
textbox=gr.Textbox(placeholder="Type your query, human..."),
|
| 232 |
)
|
| 233 |
|
|
|
|
| 88 |
}
|
| 89 |
|
| 90 |
def query_deepseek(prompt):
|
| 91 |
+
"""Send a prompt to DeepSeek-R1 and get a clean response in English."""
|
| 92 |
payload = {
|
| 93 |
"inputs": prompt,
|
| 94 |
"parameters": {
|
| 95 |
+
"max_new_tokens": 80, # Limit response length
|
| 96 |
+
"temperature": 0.5, # Less randomness
|
| 97 |
+
"top_p": 0.85, # Focused sampling
|
| 98 |
"stop": ["\n", "User:", "Assistant:"] # Stop at natural breaks
|
| 99 |
}
|
| 100 |
}
|
|
|
|
| 104 |
response.raise_for_status()
|
| 105 |
result = response.json()
|
| 106 |
generated_text = result[0]["generated_text"].strip()
|
| 107 |
+
# Remove the prompt if echoed back
|
| 108 |
if prompt in generated_text:
|
| 109 |
return generated_text.replace(prompt, "").strip()
|
| 110 |
return generated_text
|
|
|
|
| 115 |
|
| 116 |
def chat_interface(user_input, history):
|
| 117 |
"""Handle chatbot interaction with Gradio."""
|
| 118 |
+
# Build a prompt with explicit English instruction
|
| 119 |
if history:
|
| 120 |
+
prompt = "\n".join([f"U: {h[0]} | A: {h[1]}" for h in history]) + f"\nU: {user_input} | A: Respond in English: "
|
| 121 |
else:
|
| 122 |
+
prompt = f"U: {user_input} | A: Respond in English: "
|
| 123 |
|
| 124 |
+
# Get response and clean it up
|
| 125 |
response = query_deepseek(prompt)
|
| 126 |
+
response = response.replace("U: ", "").replace("| A: Respond in English: ", "").strip()
|
| 127 |
|
| 128 |
+
# Deduplicate sentences
|
|
|
|
|
|
|
|
|
|
| 129 |
sentences = response.split(". ")
|
| 130 |
unique_sentences = []
|
| 131 |
[unique_sentences.append(s) for s in sentences if s not in unique_sentences and s]
|
| 132 |
return ". ".join(unique_sentences).strip()
|
| 133 |
|
| 134 |
+
# Updated interactive CSS with a blue send button
|
| 135 |
css = """
|
| 136 |
body {
|
| 137 |
background: #000000; /* Deep black background */
|
|
|
|
| 157 |
color: #00ffcc;
|
| 158 |
}
|
| 159 |
|
|
|
|
| 160 |
.chatbot-container .message {
|
| 161 |
margin: 10px 0;
|
| 162 |
padding: 8px;
|
|
|
|
| 179 |
}
|
| 180 |
|
| 181 |
button#submit_btn {
|
| 182 |
+
background: #007bff !important; /* Blue send button */
|
| 183 |
color: #ffffff !important;
|
| 184 |
border: none !important;
|
| 185 |
padding: 10px 20px !important;
|
| 186 |
border-radius: 20px !important;
|
| 187 |
font-family: 'Courier New', monospace;
|
| 188 |
font-weight: bold;
|
| 189 |
+
box-shadow: 0 0 10px #007bff; /* Blue glow */
|
| 190 |
transition: all 0.3s ease;
|
| 191 |
}
|
| 192 |
|
| 193 |
button#submit_btn:hover {
|
| 194 |
+
background: #0056b3 !important; /* Darker blue on hover */
|
| 195 |
+
box-shadow: 0 0 15px #007bff;
|
| 196 |
transform: scale(1.1); /* Slight grow effect */
|
| 197 |
}
|
| 198 |
|
| 199 |
.title {
|
| 200 |
+
color: #00ffcc; /* Changed to cyan for consistency */
|
| 201 |
font-size: 2em;
|
| 202 |
text-align: center;
|
| 203 |
text-transform: uppercase;
|
|
|
|
| 213 |
|
| 214 |
/* Glow animation for title */
|
| 215 |
@keyframes glow {
|
| 216 |
+
from { text-shadow: 0 0 5px #00ffcc; }
|
| 217 |
+
to { text-shadow: 0 0 15px #00ffcc, 0 0 25px #00ffcc; }
|
| 218 |
}
|
| 219 |
"""
|
| 220 |
|
| 221 |
+
# Create Gradio interface
|
| 222 |
interface = gr.ChatInterface(
|
| 223 |
fn=chat_interface,
|
| 224 |
title="LocoBot: Neural Nexus",
|
| 225 |
description="A quirky AI companion powered by DeepSeek-R1. Ask away!",
|
| 226 |
css=css,
|
| 227 |
+
submit_btn=gr.Button("Send", elem_id="submit_btn"), # Blue send button
|
| 228 |
textbox=gr.Textbox(placeholder="Type your query, human..."),
|
| 229 |
)
|
| 230 |
|