jsakshi commited on
Commit
41c22b9
·
verified ·
1 Parent(s): 447d458

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -144
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": prompt,
92
  "parameters": {
93
- "max_new_tokens": 100,
94
- "temperature": 0.6,
95
- "top_p": 0.9,
96
- "repetition_penalty": 1.2 # Added to reduce repetition
 
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
- # Extract only the new response part
106
- full_response = result[0]["generated_text"].strip()
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
- prompt = f"User: {user_input}\nAssistant: "
119
- response = query_deepseek(prompt)
120
  return response
121
 
122
- # Keep your original CSS unchanged
123
- css = """
124
- @keyframes gradient {
125
- 0% { background-position: 0% 50%; }
126
- 50% { background-position: 100% 50%; }
127
- 100% { background-position: 0% 50%; }
 
 
 
 
128
  }
129
 
130
  body {
131
- background: linear-gradient(-45deg, #0f172a, #581c87, #1e1b4b, #0f172a);
132
- background-size: 400% 400%;
133
- animation: gradient 15s ease infinite;
134
- color: #ffffff;
135
- font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
136
  }
137
 
138
- .container {
139
- max-width: 800px !important;
140
- margin: 0 auto !important;
141
- padding: 20px !important;
142
- position: relative !important;
143
  }
144
 
145
  .gr-chat-interface {
146
- background: rgba(255, 255, 255, 0.05);
147
- backdrop-filter: blur(10px);
148
- border: 1px solid rgba(255, 255, 255, 0.1);
149
- border-radius: 24px;
150
- padding: 25px;
151
- box-shadow:
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: 100%;
175
- height: 100%;
176
- background: radial-gradient(circle, rgba(59, 130, 246, 0.1) 0%, transparent 70%);
177
- z-index: -1;
178
- }
179
-
180
- .title {
181
- background: linear-gradient(to right, #c084fc, #f0abfc, #93c5fd);
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: linear-gradient(to bottom, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.2));
202
- border: 1px solid rgba(255, 255, 255, 0.05);
203
- border-radius: 16px;
204
- padding: 20px;
205
- margin-bottom: 20px;
206
- height: 500px;
207
- overflow-y: auto;
208
  }
209
 
210
  .message {
211
- padding: 12px 20px;
212
- margin: 8px 0;
213
- border-radius: 16px;
214
- animation: fadeIn 0.3s ease-out;
 
 
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
- background: linear-gradient(to right, rgba(147, 51, 234, 0.1), rgba(236, 72, 153, 0.1));
231
- border-left: 4px solid #c084fc;
232
- margin-left: 20px;
233
  }
234
 
235
  .bot-message {
236
- background: linear-gradient(to right, rgba(59, 130, 246, 0.1), rgba(14, 165, 233, 0.1));
237
- border-right: 4px solid #60a5fa;
238
- margin-right: 20px;
239
  }
240
 
241
  input[type="text"] {
242
- background: rgba(0, 0, 0, 0.2) !important;
243
- border: 2px solid rgba(255, 255, 255, 0.1) !important;
244
- border-radius: 12px !important;
245
- color: #ffffff !important;
246
- padding: 15px !important;
247
- font-size: 1.1em !important;
248
- transition: all 0.3s ease !important;
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(135deg, #c084fc 0%, #60a5fa 100%) !important;
259
- color: #ffffff !important;
260
  border: none !important;
261
- padding: 12px 30px !important;
262
- border-radius: 12px !important;
263
- font-size: 1.1em !important;
264
- font-weight: 600 !important;
265
- transition: all 0.3s ease !important;
266
  text-transform: uppercase !important;
267
- letter-spacing: 1px !important;
268
- backdrop-filter: blur(5px) !important;
269
  }
270
 
271
  #submit_btn:hover {
272
- transform: translateY(-2px) !important;
273
- box-shadow: 0 5px 15px rgba(147, 51, 234, 0.3) !important;
274
- background: linear-gradient(135deg, #a855f7 0%, #3b82f6 100%) !important;
 
 
 
 
 
 
 
275
  }
276
 
277
- #submit_btn:active {
278
- transform: translateY(1px) !important;
 
 
 
279
  }
280
 
281
- /* Custom Scrollbar */
282
  ::-webkit-scrollbar {
283
  width: 8px;
284
  }
285
 
286
- ::-webkit-scrollbar-track {
287
- background: rgba(0, 0, 0, 0.2);
288
  border-radius: 4px;
289
  }
290
 
291
- ::-webkit-scrollbar-thumb {
292
- background: linear-gradient(to bottom, #c084fc, #60a5fa);
293
- border-radius: 4px;
 
294
  }
295
 
296
- ::-webkit-scrollbar-thumb:hover {
297
- background: linear-gradient(to bottom, #a855f7, #3b82f6);
 
 
 
 
298
  }
299
  """
300
 
301
  interface = gr.ChatInterface(
302
  fn=chat_interface,
303
- title="LocoBot: DeepSeek-R1 Chatbot",
304
- description="Chat with DeepSeek-R1 powered by Hugging Face Inference API.",
305
- theme="default",
306
- css=css
 
 
 
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__":