jsakshi commited on
Commit
7e93b8b
·
verified ·
1 Parent(s): c82ba5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +174 -71
app.py CHANGED
@@ -93,9 +93,9 @@ def query_deepseek(prompt):
93
  payload = {
94
  "inputs": prompt,
95
  "parameters": {
96
- "max_new_tokens": 100, # Slightly increased for flexibility
97
- "temperature": 0.7, # Balanced creativity
98
- "top_p": 0.9 # Relaxed sampling
99
  }
100
  }
101
 
@@ -104,11 +104,12 @@ def query_deepseek(prompt):
104
  response.raise_for_status()
105
  result = response.json()
106
  generated_text = result[0]["generated_text"].strip()
107
- print(f"Raw API response: {generated_text}") # Debug output
108
- # Remove the prompt if included
109
- if generated_text.startswith(prompt):
110
- return generated_text[len(prompt):].strip()
111
- return generated_text
 
112
  except requests.exceptions.RequestException as e:
113
  return f"Error: API request failed - {str(e)}"
114
  except (KeyError, IndexError):
@@ -116,100 +117,202 @@ def query_deepseek(prompt):
116
 
117
  def chat_interface(user_input, history):
118
  """Handle chatbot interaction with Gradio."""
119
- # Simple prompt with English instruction
120
- prompt = f"User: {user_input}\nAssistant: Respond in English: "
121
  response = query_deepseek(prompt)
122
-
123
- # Clean up the response
124
- response = response.replace("Assistant: Respond in English: ", "").strip()
125
- print(f"Final response: {response}") # Debug output
126
- return response if response else "Sorry, I couldn’t generate a response. Try again!"
127
 
128
- # Simplified interactive CSS with a blue send button
129
  css = """
 
 
 
 
 
 
130
  body {
131
- background: #000000; /* Black background */
132
- color: #ffffff; /* White text for readability */
133
- font-family: 'Courier New', monospace;
 
 
 
 
 
 
 
 
 
134
  }
135
 
136
  .gr-chat-interface {
137
- background: rgba(0, 0, 0, 0.9);
138
- border: 1px solid #ffffff;
139
- border-radius: 10px;
140
- padding: 20px;
141
- max-width: 700px;
142
- margin: 20px auto;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
 
145
- .chatbot-container {
146
- height: 400px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  overflow-y: auto;
148
- background: #1a1a1a;
149
- border-radius: 8px;
150
- padding: 10px;
151
- color: #ffffff;
152
  }
153
 
154
- .chatbot-container .message {
155
- margin: 10px 0;
156
- padding: 8px;
157
- border-radius: 5px;
158
- background: #333333;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
160
 
161
- input {
162
- background: #1a1a1a !important;
 
 
163
  color: #ffffff !important;
164
- border: 1px solid #ffffff !important;
165
- border-radius: 5px !important;
166
- padding: 10px !important;
167
- font-family: 'Courier New', monospace;
 
 
 
 
 
168
  }
169
 
170
- button#submit_btn {
171
- background: #007bff !important; /* Blue send button */
172
  color: #ffffff !important;
173
  border: none !important;
174
- padding: 10px 20px !important;
175
- border-radius: 20px !important;
176
- font-family: 'Courier New', monospace;
177
- font-weight: bold;
178
- box-shadow: 0 0 10px #007bff;
179
- transition: all 0.3s ease;
 
 
180
  }
181
 
182
- button#submit_btn:hover {
183
- background: #0056b3 !important; /* Darker blue on hover */
184
- box-shadow: 0 0 15px #007bff;
185
- transform: scale(1.1);
186
  }
187
 
188
- .title {
189
- color: #007bff; /* Blue title to match button */
190
- font-size: 2em;
191
- text-align: center;
192
- text-transform: uppercase;
193
- letter-spacing: 2px;
194
  }
195
 
196
- .description {
197
- color: #ffffff;
198
- text-align: center;
199
- font-size: 0.9em;
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  }
201
  """
202
 
203
- # Create Gradio interface
204
  interface = gr.ChatInterface(
205
  fn=chat_interface,
206
- title="LocoBot: Core Unit",
207
- description="A straightforward AI powered by DeepSeek-R1. Ask me anything!",
208
  css=css,
209
- submit_btn=gr.Button("Send", elem_id="submit_btn"), # Blue send button
210
- textbox=gr.Textbox(placeholder="Enter your question..."),
 
 
 
 
211
  )
212
 
213
  if __name__ == "__main__":
214
- interface.launch(server_name="0.0.0.0", server_port=7860)
215
-
 
93
  payload = {
94
  "inputs": prompt,
95
  "parameters": {
96
+ "max_new_tokens": 100,
97
+ "temperature": 0.7,
98
+ "top_p": 0.9
99
  }
100
  }
101
 
 
104
  response.raise_for_status()
105
  result = response.json()
106
  generated_text = result[0]["generated_text"].strip()
107
+
108
+ # Extract only the assistant's response after the prompt
109
+ if "Assistant:" in generated_text:
110
+ response_parts = generated_text.split("Assistant:")
111
+ return response_parts[-1].replace("Respond in English:", "").strip()
112
+ return generated_text.replace("Respond in English:", "").strip()
113
  except requests.exceptions.RequestException as e:
114
  return f"Error: API request failed - {str(e)}"
115
  except (KeyError, IndexError):
 
117
 
118
  def chat_interface(user_input, history):
119
  """Handle chatbot interaction with Gradio."""
120
+ prompt = f"User: {user_input}\nAssistant: "
 
121
  response = query_deepseek(prompt)
122
+ return response if response else "I apologize, but I couldn't generate a response. Please try again!"
 
 
 
 
123
 
124
+ # Enhanced Modern CSS
125
  css = """
126
+ @keyframes gradient {
127
+ 0% { background-position: 0% 50%; }
128
+ 50% { background-position: 100% 50%; }
129
+ 100% { background-position: 0% 50%; }
130
+ }
131
+
132
  body {
133
+ background: linear-gradient(-45deg, #0f172a, #581c87, #1e1b4b, #0f172a);
134
+ background-size: 400% 400%;
135
+ animation: gradient 15s ease infinite;
136
+ color: #ffffff;
137
+ font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
138
+ }
139
+
140
+ .container {
141
+ max-width: 800px !important;
142
+ margin: 0 auto !important;
143
+ padding: 20px !important;
144
+ position: relative !important;
145
  }
146
 
147
  .gr-chat-interface {
148
+ background: rgba(255, 255, 255, 0.05);
149
+ backdrop-filter: blur(10px);
150
+ border: 1px solid rgba(255, 255, 255, 0.1);
151
+ border-radius: 24px;
152
+ padding: 25px;
153
+ box-shadow:
154
+ 0 8px 32px rgba(0, 0, 0, 0.2),
155
+ 0 0 0 1px rgba(255, 255, 255, 0.05);
156
+ position: relative;
157
+ overflow: hidden;
158
+ }
159
+
160
+ .gr-chat-interface::before {
161
+ content: '';
162
+ position: absolute;
163
+ top: -50%;
164
+ right: -50%;
165
+ width: 100%;
166
+ height: 100%;
167
+ background: radial-gradient(circle, rgba(147, 51, 234, 0.1) 0%, transparent 70%);
168
+ z-index: -1;
169
+ }
170
+
171
+ .gr-chat-interface::after {
172
+ content: '';
173
+ position: absolute;
174
+ bottom: -50%;
175
+ left: -50%;
176
+ width: 100%;
177
+ height: 100%;
178
+ background: radial-gradient(circle, rgba(59, 130, 246, 0.1) 0%, transparent 70%);
179
+ z-index: -1;
180
  }
181
 
182
+ .title {
183
+ background: linear-gradient(to right, #c084fc, #f0abfc, #93c5fd);
184
+ -webkit-background-clip: text;
185
+ background-clip: text;
186
+ color: transparent;
187
+ font-size: 2.5em;
188
+ text-align: center;
189
+ margin-bottom: 10px;
190
+ font-weight: bold;
191
+ animation: gradient 6s ease infinite;
192
+ background-size: 200% auto;
193
+ }
194
+
195
+ .description {
196
+ color: rgba(255, 255, 255, 0.7);
197
+ text-align: center;
198
+ font-size: 1.1em;
199
+ margin-bottom: 30px;
200
+ }
201
+
202
+ .chatbot {
203
+ background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.2));
204
+ border: 1px solid rgba(255, 255, 255, 0.05);
205
+ border-radius: 16px;
206
+ padding: 20px;
207
+ margin-bottom: 20px;
208
+ height: 500px;
209
  overflow-y: auto;
 
 
 
 
210
  }
211
 
212
+ .message {
213
+ padding: 12px 20px;
214
+ margin: 8px 0;
215
+ border-radius: 16px;
216
+ animation: fadeIn 0.3s ease-out;
217
+ backdrop-filter: blur(5px);
218
+ }
219
+
220
+ @keyframes fadeIn {
221
+ from {
222
+ opacity: 0;
223
+ transform: translateY(10px);
224
+ }
225
+ to {
226
+ opacity: 1;
227
+ transform: translateY(0);
228
+ }
229
+ }
230
+
231
+ .user-message {
232
+ background: linear-gradient(to right, rgba(147, 51, 234, 0.1), rgba(236, 72, 153, 0.1));
233
+ border-left: 4px solid #c084fc;
234
+ margin-left: 20px;
235
+ }
236
+
237
+ .bot-message {
238
+ background: linear-gradient(to right, rgba(59, 130, 246, 0.1), rgba(14, 165, 233, 0.1));
239
+ border-right: 4px solid #60a5fa;
240
+ margin-right: 20px;
241
  }
242
 
243
+ input[type="text"] {
244
+ background: rgba(0, 0, 0, 0.2) !important;
245
+ border: 2px solid rgba(255, 255, 255, 0.1) !important;
246
+ border-radius: 12px !important;
247
  color: #ffffff !important;
248
+ padding: 15px !important;
249
+ font-size: 1.1em !important;
250
+ transition: all 0.3s ease !important;
251
+ backdrop-filter: blur(5px) !important;
252
+ }
253
+
254
+ input[type="text"]:focus {
255
+ border-color: #c084fc !important;
256
+ box-shadow: 0 0 15px rgba(147, 51, 234, 0.2) !important;
257
  }
258
 
259
+ #submit_btn {
260
+ background: linear-gradient(135deg, #c084fc 0%, #60a5fa 100%) !important;
261
  color: #ffffff !important;
262
  border: none !important;
263
+ padding: 12px 30px !important;
264
+ border-radius: 12px !important;
265
+ font-size: 1.1em !important;
266
+ font-weight: 600 !important;
267
+ transition: all 0.3s ease !important;
268
+ text-transform: uppercase !important;
269
+ letter-spacing: 1px !important;
270
+ backdrop-filter: blur(5px) !important;
271
  }
272
 
273
+ #submit_btn:hover {
274
+ transform: translateY(-2px) !important;
275
+ box-shadow: 0 5px 15px rgba(147, 51, 234, 0.3) !important;
276
+ background: linear-gradient(135deg, #a855f7 0%, #3b82f6 100%) !important;
277
  }
278
 
279
+ #submit_btn:active {
280
+ transform: translateY(1px) !important;
 
 
 
 
281
  }
282
 
283
+ /* Custom Scrollbar */
284
+ ::-webkit-scrollbar {
285
+ width: 8px;
286
+ }
287
+
288
+ ::-webkit-scrollbar-track {
289
+ background: rgba(0, 0, 0, 0.2);
290
+ border-radius: 4px;
291
+ }
292
+
293
+ ::-webkit-scrollbar-thumb {
294
+ background: linear-gradient(to bottom, #c084fc, #60a5fa);
295
+ border-radius: 4px;
296
+ }
297
+
298
+ ::-webkit-scrollbar-thumb:hover {
299
+ background: linear-gradient(to bottom, #a855f7, #3b82f6);
300
  }
301
  """
302
 
303
+ # Create Gradio interface with enhanced styling
304
  interface = gr.ChatInterface(
305
  fn=chat_interface,
306
+ title="Neural Nexus AI",
307
+ description="Your gateway to intelligent conversation",
308
  css=css,
309
+ submit_btn=gr.Button("Send", elem_id="submit_btn"),
310
+ textbox=gr.Textbox(
311
+ placeholder="Send a message...",
312
+ container=False,
313
+ autofocus=True
314
+ ),
315
  )
316
 
317
  if __name__ == "__main__":
318
+ interface.launch(server_name="0.0.0.0", server_port=7860)