Update app.py
Browse files
app.py
CHANGED
|
@@ -87,13 +87,15 @@ HEADERS = {
|
|
| 87 |
|
| 88 |
def query_deepseek(prompt):
|
| 89 |
"""Send a prompt to DeepSeek-R1 and get a response."""
|
|
|
|
| 90 |
payload = {
|
| 91 |
-
"inputs":
|
| 92 |
"parameters": {
|
| 93 |
-
"max_new_tokens":
|
| 94 |
-
"temperature": 0.
|
| 95 |
-
"top_p": 0.
|
| 96 |
-
"repetition_penalty": 1.
|
|
|
|
| 97 |
}
|
| 98 |
}
|
| 99 |
|
|
@@ -101,56 +103,45 @@ def query_deepseek(prompt):
|
|
| 101 |
response = requests.post(MODEL_URL, headers=HEADERS, json=payload)
|
| 102 |
response.raise_for_status()
|
| 103 |
result = response.json()
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
if "Assistant: " in full_response:
|
| 108 |
-
# Split and get only the last assistant response
|
| 109 |
-
return full_response.split("Assistant: ")[-1].strip()
|
| 110 |
-
return full_response
|
| 111 |
-
except requests.exceptions.RequestException as e:
|
| 112 |
-
return f"Error: Could not connect to the API - {str(e)}"
|
| 113 |
-
except (KeyError, IndexError):
|
| 114 |
-
return "Error: Unexpected response format from API"
|
| 115 |
|
| 116 |
def chat_interface(user_input, history):
|
| 117 |
"""Handle chatbot interaction with Gradio."""
|
| 118 |
-
|
| 119 |
-
response = query_deepseek(prompt)
|
| 120 |
return response
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
}
|
| 129 |
|
| 130 |
body {
|
| 131 |
-
background:
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
| 136 |
}
|
| 137 |
|
| 138 |
-
.container {
|
| 139 |
-
|
| 140 |
-
margin: 0 auto !important;
|
| 141 |
-
padding: 20px !important;
|
| 142 |
-
position: relative !important;
|
| 143 |
}
|
| 144 |
|
| 145 |
.gr-chat-interface {
|
| 146 |
-
background: rgba(
|
| 147 |
-
|
| 148 |
-
border:
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
0 8px 32px rgba(0, 0, 0, 0.2),
|
| 153 |
-
0 0 0 1px rgba(255, 255, 255, 0.05);
|
| 154 |
position: relative;
|
| 155 |
overflow: hidden;
|
| 156 |
}
|
|
@@ -159,151 +150,121 @@ body {
|
|
| 159 |
content: '';
|
| 160 |
position: absolute;
|
| 161 |
top: -50%;
|
| 162 |
-
right: -50%;
|
| 163 |
-
width: 100%;
|
| 164 |
-
height: 100%;
|
| 165 |
-
background: radial-gradient(circle, rgba(147, 51, 234, 0.1) 0%, transparent 70%);
|
| 166 |
-
z-index: -1;
|
| 167 |
-
}
|
| 168 |
-
|
| 169 |
-
.gr-chat-interface::after {
|
| 170 |
-
content: '';
|
| 171 |
-
position: absolute;
|
| 172 |
-
bottom: -50%;
|
| 173 |
left: -50%;
|
| 174 |
-
width:
|
| 175 |
-
height:
|
| 176 |
-
background:
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
-webkit-background-clip: text;
|
| 183 |
-
background-clip: text;
|
| 184 |
-
color: transparent;
|
| 185 |
-
font-size: 2.5em;
|
| 186 |
-
text-align: center;
|
| 187 |
-
margin-bottom: 10px;
|
| 188 |
-
font-weight: bold;
|
| 189 |
-
animation: gradient 6s ease infinite;
|
| 190 |
-
background-size: 200% auto;
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
-
.description {
|
| 194 |
-
color: rgba(255, 255, 255, 0.7);
|
| 195 |
-
text-align: center;
|
| 196 |
-
font-size: 1.1em;
|
| 197 |
-
margin-bottom: 30px;
|
| 198 |
}
|
| 199 |
|
| 200 |
.chatbot {
|
| 201 |
-
background:
|
| 202 |
-
border: 1px solid
|
| 203 |
-
border-radius:
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
height: 500px;
|
| 207 |
-
overflow-y: auto;
|
| 208 |
}
|
| 209 |
|
| 210 |
.message {
|
| 211 |
-
padding:
|
| 212 |
-
margin:
|
| 213 |
-
border-radius:
|
| 214 |
-
|
|
|
|
|
|
|
| 215 |
backdrop-filter: blur(5px);
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
@keyframes fadeIn {
|
| 219 |
-
from {
|
| 220 |
-
opacity: 0;
|
| 221 |
-
transform: translateY(10px);
|
| 222 |
-
}
|
| 223 |
-
to {
|
| 224 |
-
opacity: 1;
|
| 225 |
-
transform: translateY(0);
|
| 226 |
-
}
|
| 227 |
}
|
| 228 |
|
| 229 |
.user-message {
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
margin-left: 20px;
|
| 233 |
}
|
| 234 |
|
| 235 |
.bot-message {
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
margin-right: 20px;
|
| 239 |
}
|
| 240 |
|
| 241 |
input[type="text"] {
|
| 242 |
-
background: rgba(0, 0, 0, 0.
|
| 243 |
-
border:
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
backdrop-filter: blur(5px) !important;
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
input[type="text"]:focus {
|
| 253 |
-
border-color: #c084fc !important;
|
| 254 |
-
box-shadow: 0 0 15px rgba(147, 51, 234, 0.2) !important;
|
| 255 |
}
|
| 256 |
|
| 257 |
#submit_btn {
|
| 258 |
-
background: linear-gradient(
|
| 259 |
-
color: #
|
| 260 |
border: none !important;
|
| 261 |
-
padding: 12px
|
| 262 |
-
border-radius:
|
| 263 |
-
font-
|
| 264 |
-
font-weight: 600 !important;
|
| 265 |
-
transition: all 0.3s ease !important;
|
| 266 |
text-transform: uppercase !important;
|
| 267 |
-
letter-spacing:
|
| 268 |
-
|
| 269 |
}
|
| 270 |
|
| 271 |
#submit_btn:hover {
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
}
|
| 276 |
|
| 277 |
-
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
| 279 |
}
|
| 280 |
|
| 281 |
-
/* Custom Scrollbar */
|
| 282 |
::-webkit-scrollbar {
|
| 283 |
width: 8px;
|
| 284 |
}
|
| 285 |
|
| 286 |
-
::-webkit-scrollbar-
|
| 287 |
-
background:
|
| 288 |
border-radius: 4px;
|
| 289 |
}
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
|
|
|
| 294 |
}
|
| 295 |
|
| 296 |
-
|
| 297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
}
|
| 299 |
"""
|
| 300 |
|
| 301 |
interface = gr.ChatInterface(
|
| 302 |
fn=chat_interface,
|
| 303 |
-
title="
|
| 304 |
-
description="
|
| 305 |
-
theme=
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
| 307 |
)
|
| 308 |
|
| 309 |
if __name__ == "__main__":
|
|
|
|
| 87 |
|
| 88 |
def query_deepseek(prompt):
|
| 89 |
"""Send a prompt to DeepSeek-R1 and get a response."""
|
| 90 |
+
english_prompt = f"Respond in English: {prompt}" # Force English response
|
| 91 |
payload = {
|
| 92 |
+
"inputs": english_prompt,
|
| 93 |
"parameters": {
|
| 94 |
+
"max_new_tokens": 150,
|
| 95 |
+
"temperature": 0.7,
|
| 96 |
+
"top_p": 0.85,
|
| 97 |
+
"repetition_penalty": 1.3,
|
| 98 |
+
"do_sample": True
|
| 99 |
}
|
| 100 |
}
|
| 101 |
|
|
|
|
| 103 |
response = requests.post(MODEL_URL, headers=HEADERS, json=payload)
|
| 104 |
response.raise_for_status()
|
| 105 |
result = response.json()
|
| 106 |
+
return result[0]["generated_text"].split("Assistant:")[-1].strip()
|
| 107 |
+
except Exception as e:
|
| 108 |
+
return f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
def chat_interface(user_input, history):
|
| 111 |
"""Handle chatbot interaction with Gradio."""
|
| 112 |
+
response = query_deepseek(user_input)
|
|
|
|
| 113 |
return response
|
| 114 |
|
| 115 |
+
cyberpunk_css = """
|
| 116 |
+
@keyframes matrix {
|
| 117 |
+
0% { background-position: 0% 0%; }
|
| 118 |
+
100% { background-position: 100% 100%; }
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
@keyframes glitch {
|
| 122 |
+
2% { transform: translate(2px, 0) skew(0deg); }
|
| 123 |
+
4% { transform: translate(-2px, 0) skew(0deg); }
|
| 124 |
+
96% { transform: translate(0, 0) skew(0deg); }
|
| 125 |
}
|
| 126 |
|
| 127 |
body {
|
| 128 |
+
background: #0a0a14;
|
| 129 |
+
color: #00ff9d;
|
| 130 |
+
font-family: 'Courier New', monospace;
|
| 131 |
+
overflow-x: hidden;
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
+
.gradio-container {
|
| 135 |
+
background: radial-gradient(circle at center, #1a1a2e 0%, #0a0a14 100%);
|
|
|
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
|
| 138 |
.gr-chat-interface {
|
| 139 |
+
background: rgba(10, 10, 20, 0.95) !important;
|
| 140 |
+
border: 1px solid #4d00ff !important;
|
| 141 |
+
border-radius: 10px;
|
| 142 |
+
box-shadow: 0 0 20px #4d00ff33,
|
| 143 |
+
0 0 40px #4d00ff33,
|
| 144 |
+
inset 0 0 15px #4d00ff33;
|
|
|
|
|
|
|
| 145 |
position: relative;
|
| 146 |
overflow: hidden;
|
| 147 |
}
|
|
|
|
| 150 |
content: '';
|
| 151 |
position: absolute;
|
| 152 |
top: -50%;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
left: -50%;
|
| 154 |
+
width: 200%;
|
| 155 |
+
height: 200%;
|
| 156 |
+
background: linear-gradient(45deg,
|
| 157 |
+
transparent 45%,
|
| 158 |
+
#4d00ff 50%,
|
| 159 |
+
transparent 55%);
|
| 160 |
+
animation: matrix 20s linear infinite;
|
| 161 |
+
opacity: 0.1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
}
|
| 163 |
|
| 164 |
.chatbot {
|
| 165 |
+
background: rgba(0, 0, 0, 0.3) !important;
|
| 166 |
+
border: 1px solid #00ff9d33 !important;
|
| 167 |
+
border-radius: 8px;
|
| 168 |
+
margin: 15px;
|
| 169 |
+
height: 60vh;
|
|
|
|
|
|
|
| 170 |
}
|
| 171 |
|
| 172 |
.message {
|
| 173 |
+
padding: 15px;
|
| 174 |
+
margin: 10px;
|
| 175 |
+
border-radius: 5px;
|
| 176 |
+
position: relative;
|
| 177 |
+
background: rgba(0, 255, 157, 0.05) !important;
|
| 178 |
+
border: 1px solid #00ff9d33 !important;
|
| 179 |
backdrop-filter: blur(5px);
|
| 180 |
+
animation: glitch 5s infinite;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
}
|
| 182 |
|
| 183 |
.user-message {
|
| 184 |
+
border-left: 3px solid #4d00ff !important;
|
| 185 |
+
margin-left: 30px;
|
|
|
|
| 186 |
}
|
| 187 |
|
| 188 |
.bot-message {
|
| 189 |
+
border-right: 3px solid #00ff9d !important;
|
| 190 |
+
margin-right: 30px;
|
|
|
|
| 191 |
}
|
| 192 |
|
| 193 |
input[type="text"] {
|
| 194 |
+
background: rgba(0, 0, 0, 0.5) !important;
|
| 195 |
+
border: 1px solid #4d00ff !important;
|
| 196 |
+
color: #00ff9d !important;
|
| 197 |
+
padding: 12px !important;
|
| 198 |
+
font-family: 'Courier New' !important;
|
| 199 |
+
border-radius: 5px !important;
|
| 200 |
+
box-shadow: 0 0 10px #4d00ff33 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
}
|
| 202 |
|
| 203 |
#submit_btn {
|
| 204 |
+
background: linear-gradient(45deg, #4d00ff, #00ff9d) !important;
|
| 205 |
+
color: #000 !important;
|
| 206 |
border: none !important;
|
| 207 |
+
padding: 12px 25px !important;
|
| 208 |
+
border-radius: 5px !important;
|
| 209 |
+
font-weight: bold !important;
|
|
|
|
|
|
|
| 210 |
text-transform: uppercase !important;
|
| 211 |
+
letter-spacing: 2px !important;
|
| 212 |
+
transition: 0.3s !important;
|
| 213 |
}
|
| 214 |
|
| 215 |
#submit_btn:hover {
|
| 216 |
+
box-shadow: 0 0 20px #00ff9d66 !important;
|
| 217 |
+
transform: scale(1.05) !important;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
.title {
|
| 221 |
+
font-size: 2.5em;
|
| 222 |
+
text-align: center;
|
| 223 |
+
text-shadow: 0 0 10px #00ff9d;
|
| 224 |
+
animation: glitch 5s infinite;
|
| 225 |
+
position: relative;
|
| 226 |
}
|
| 227 |
|
| 228 |
+
.description {
|
| 229 |
+
color: #4d00ff;
|
| 230 |
+
text-align: center;
|
| 231 |
+
font-size: 1.2em;
|
| 232 |
+
margin-bottom: 2em;
|
| 233 |
}
|
| 234 |
|
|
|
|
| 235 |
::-webkit-scrollbar {
|
| 236 |
width: 8px;
|
| 237 |
}
|
| 238 |
|
| 239 |
+
::-webkit-scrollbar-thumb {
|
| 240 |
+
background: linear-gradient(#4d00ff, #00ff9d);
|
| 241 |
border-radius: 4px;
|
| 242 |
}
|
| 243 |
|
| 244 |
+
@keyframes terminal-blink {
|
| 245 |
+
0% { opacity: 1; }
|
| 246 |
+
50% { opacity: 0; }
|
| 247 |
+
100% { opacity: 1; }
|
| 248 |
}
|
| 249 |
|
| 250 |
+
.message::after {
|
| 251 |
+
content: '|';
|
| 252 |
+
animation: terminal-blink 1s infinite;
|
| 253 |
+
color: #00ff9d;
|
| 254 |
+
position: absolute;
|
| 255 |
+
right: 10px;
|
| 256 |
}
|
| 257 |
"""
|
| 258 |
|
| 259 |
interface = gr.ChatInterface(
|
| 260 |
fn=chat_interface,
|
| 261 |
+
title="⚡ CYBER-CHAT 3000 ⚡",
|
| 262 |
+
description="> ENGLISH-ONLY NEURAL INTERFACE // v1.3.37",
|
| 263 |
+
theme=gr.themes.Default(
|
| 264 |
+
primary_hue="cyan",
|
| 265 |
+
secondary_hue="purple"
|
| 266 |
+
),
|
| 267 |
+
css=cyberpunk_css
|
| 268 |
)
|
| 269 |
|
| 270 |
if __name__ == "__main__":
|