rafaldembski commited on
Commit
08633e2
1 Parent(s): 51a778f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +176 -37
app.py CHANGED
@@ -42,7 +42,6 @@ def respond(message, chat_history, model, system_prompt, thinking_budget, api_ke
42
  completion = client.chat.completions.create(model=model, messages=messages)
43
  response = completion.choices[0].message.content
44
  thinking_time = time.time() - start_time
45
- # Jeśli API zwraca liczbę tokenów, można je tutaj dodać
46
  tokens_used = completion.usage.total_tokens if hasattr(completion, 'usage') else 'N/A'
47
  return response, thinking_time, tokens_used
48
  except Exception as e:
@@ -164,9 +163,9 @@ To provide the most comprehensive and well-thought-out answers, follow this enha
164
  custom_css = """
165
  /* Ogólne tło aplikacji */
166
  body {
167
- background-color: #FFFFFF; /* Jasne tło */
168
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
169
- color: #333333; /* Ciemny kolor tekstu dla kontrastu */
170
  }
171
 
172
  /* Główny kontener */
@@ -179,29 +178,29 @@ body {
179
 
180
  /* Nagłówek */
181
  h1, .gr-markdown h1 {
182
- color: #4A90E2; /* Niebieski kolor nagłówka */
183
  text-align: center;
184
  margin-bottom: 10px;
185
  font-size: 2.5em;
186
  }
187
 
188
  h2, .gr-markdown h2 {
189
- color: #333333;
190
  }
191
 
192
  /* Karty i panele */
193
  #component-0, #component-1, #component-2, #component-3, #component-4, #component-5 {
194
- background-color: #F9F9F9; /* Jasne tło dla boxów */
195
  border-radius: 12px;
196
  padding: 20px;
197
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
198
  margin-bottom: 20px;
199
- width: 100%; /* Rozciągnięcie na całą szerokość */
200
  }
201
 
202
  /* Przycisk Wyślij */
203
  button.primary {
204
- background-color: #4A90E2;
205
  color: #FFFFFF;
206
  border: none;
207
  border-radius: 8px;
@@ -213,12 +212,12 @@ button.primary {
213
  }
214
 
215
  button.primary:hover {
216
- background-color: #357AB8;
217
  }
218
 
219
  /* Przycisk Wyczyść */
220
  button.secondary {
221
- background-color: #6C757D;
222
  color: #FFFFFF;
223
  border: none;
224
  border-radius: 8px;
@@ -230,25 +229,25 @@ button.secondary {
230
  }
231
 
232
  button.secondary:hover {
233
- background-color: #5A6268;
234
  }
235
 
236
  /* Pole tekstowe wiadomości */
237
  textarea {
238
- background-color: #FFFFFF;
239
- border: 1px solid #CED4DA;
240
  border-radius: 8px;
241
  padding: 12px;
242
  font-size: 16px;
243
  resize: none;
244
  transition: border-color 0.3s ease;
245
- color: #333333;
246
  }
247
 
248
  textarea:focus {
249
- border-color: #4A90E2;
250
  outline: none;
251
- box-shadow: 0 0 5px rgba(74, 144, 226, 0.5);
252
  }
253
 
254
  /* Chatbot */
@@ -256,37 +255,179 @@ textarea:focus {
256
  height: 600px;
257
  overflow-y: auto;
258
  padding: 10px;
259
- border: 1px solid #CED4DA;
260
  border-radius: 8px;
261
- background-color: #FFFFFF;
262
- color: #333333;
263
  }
264
 
265
  /* Panel Informacyjny */
266
  #info-panel {
267
- background-color: #F1F1F1;
268
- border: 1px solid #CED4DA;
269
  border-radius: 8px;
270
  padding: 15px;
271
  font-size: 14px;
272
- color: #333333;
273
  }
274
 
275
  /* Linki */
276
  a {
277
- color: #4A90E2;
278
  text-decoration: none;
279
  }
280
 
281
  a:hover {
282
  text-decoration: underline;
283
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  """
285
 
286
  # Tworzenie interfejsu Gradio z niestandardowym CSS
287
  with gr.Blocks(css=custom_css) as demo:
288
- # Nagłówek
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  gr.Markdown("# 🧠 **D-LOGIC: Twój Inteligentny Asystent AI**")
 
 
290
  gr.Markdown("""
291
  **D-LOGIC** to zaawansowany asystent AI stworzony przez Rafała Dembskiego. Dzięki zaawansowanemu procesowi myślowemu, **D-LOGIC** analizuje, planuje i dostarcza precyzyjne odpowiedzi na Twoje pytania, zapewniając jednocześnie interaktywną i angażującą konwersację.
292
 
@@ -296,7 +437,7 @@ with gr.Blocks(css=custom_css) as demo:
296
  - **Generowanie Rozwiązań**: Proponowanie najlepszych możliwych odpowiedzi.
297
  - **Refleksja**: Samoocena jakości odpowiedzi i procesów myślowych.
298
  """)
299
-
300
  # Wybór modelu i budżet myślenia
301
  with gr.Row():
302
  with gr.Column(scale=1):
@@ -315,7 +456,7 @@ with gr.Blocks(css=custom_css) as demo:
315
  label="🧩 Budżet Myślenia",
316
  info="Maksymalna liczba kroków, które model może przemyśleć"
317
  )
318
-
319
  # Sekcja czatu
320
  chatbot = gr.Chatbot(
321
  label="💬 Chat",
@@ -326,7 +467,7 @@ with gr.Blocks(css=custom_css) as demo:
326
  layout="vertical",
327
  height=600
328
  )
329
-
330
  # Pole do wpisywania wiadomości
331
  with gr.Row():
332
  msg = gr.Textbox(
@@ -334,38 +475,36 @@ with gr.Blocks(css=custom_css) as demo:
334
  placeholder="Wprowadź swoją wiadomość...",
335
  lines=1
336
  )
337
-
338
  # Przycisk Wyślij i Wyczyść
339
  with gr.Row():
340
  submit_button = gr.Button("🚀 Wyślij", variant="primary")
341
  clear_button = gr.Button("🧹 Wyczyść Chat", variant="secondary")
342
-
343
  # Panel Informacyjny
344
  info_panel = gr.Markdown(
345
  value="**Informacje:**\nCzas myślenia i inne dane będą tutaj wyświetlane.",
346
  elem_id="info-panel"
347
  )
348
-
349
  # Akcje przycisków
350
  clear_button.click(
351
  fn=lambda: ([], "", "**Informacje:**\nCzas myślenia i inne dane zostały zresetowane."),
352
  inputs=None,
353
  outputs=[chatbot, msg, info_panel]
354
  )
355
-
356
  # Przesyłanie wiadomości poprzez Enter lub kliknięcie przycisku Wyślij
357
  msg.submit(
358
  fn=generate,
359
- inputs=[msg, chatbot, model, thinking_budget],
360
  outputs=[chatbot, msg, info_panel]
361
  )
362
  submit_button.click(
363
  fn=generate,
364
- inputs=[msg, chatbot, model, thinking_budget],
365
  outputs=[chatbot, msg, info_panel]
366
  )
367
-
368
- # Usunięcie Stopki (brak kodu dla stopki)
369
-
370
  # Uruchomienie aplikacji Gradio na Hugging Face Spaces
371
  demo.launch(share=False, show_api=False)
 
42
  completion = client.chat.completions.create(model=model, messages=messages)
43
  response = completion.choices[0].message.content
44
  thinking_time = time.time() - start_time
 
45
  tokens_used = completion.usage.total_tokens if hasattr(completion, 'usage') else 'N/A'
46
  return response, thinking_time, tokens_used
47
  except Exception as e:
 
163
  custom_css = """
164
  /* Ogólne tło aplikacji */
165
  body {
166
+ background-color: #1e293b; /* Ciemne tło pasujące do karty */
167
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
168
+ color: #cbd5e1; /* Jasny kolor tekstu dla kontrastu */
169
  }
170
 
171
  /* Główny kontener */
 
178
 
179
  /* Nagłówek */
180
  h1, .gr-markdown h1 {
181
+ color: #60a5fa; /* Niebieski kolor nagłówka */
182
  text-align: center;
183
  margin-bottom: 10px;
184
  font-size: 2.5em;
185
  }
186
 
187
  h2, .gr-markdown h2 {
188
+ color: #cbd5e1;
189
  }
190
 
191
  /* Karty i panele */
192
  #component-0, #component-1, #component-2, #component-3, #component-4, #component-5 {
193
+ background-color: #334155; /* Zamiana na ciemniejsze tło */
194
  border-radius: 12px;
195
  padding: 20px;
196
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); /* Większy kontrast dla ciemnego tła */
197
  margin-bottom: 20px;
198
+ width: 100%;
199
  }
200
 
201
  /* Przycisk Wyślij */
202
  button.primary {
203
+ background-color: #60a5fa;
204
  color: #FFFFFF;
205
  border: none;
206
  border-radius: 8px;
 
212
  }
213
 
214
  button.primary:hover {
215
+ background-color: #3b82f6;
216
  }
217
 
218
  /* Przycisk Wyczyść */
219
  button.secondary {
220
+ background-color: #64748b;
221
  color: #FFFFFF;
222
  border: none;
223
  border-radius: 8px;
 
229
  }
230
 
231
  button.secondary:hover {
232
+ background-color: #475569;
233
  }
234
 
235
  /* Pole tekstowe wiadomości */
236
  textarea {
237
+ background-color: #1e293b;
238
+ border: 1px solid #64748b;
239
  border-radius: 8px;
240
  padding: 12px;
241
  font-size: 16px;
242
  resize: none;
243
  transition: border-color 0.3s ease;
244
+ color: #cbd5e1;
245
  }
246
 
247
  textarea:focus {
248
+ border-color: #60a5fa;
249
  outline: none;
250
+ box-shadow: 0 0 5px rgba(96, 165, 250, 0.5);
251
  }
252
 
253
  /* Chatbot */
 
255
  height: 600px;
256
  overflow-y: auto;
257
  padding: 10px;
258
+ border: 1px solid #64748b;
259
  border-radius: 8px;
260
+ background-color: #1e293b;
261
+ color: #cbd5e1;
262
  }
263
 
264
  /* Panel Informacyjny */
265
  #info-panel {
266
+ background-color: #334155;
267
+ border: 1px solid #64748b;
268
  border-radius: 8px;
269
  padding: 15px;
270
  font-size: 14px;
271
+ color: #cbd5e1;
272
  }
273
 
274
  /* Linki */
275
  a {
276
+ color: #60a5fa;
277
  text-decoration: none;
278
  }
279
 
280
  a:hover {
281
  text-decoration: underline;
282
  }
283
+
284
+ /* Style dla Karty */
285
+ .custom-card {
286
+ position: relative;
287
+ border-radius: 0.75rem; /* Rounded-lg */
288
+ background-color: #1e293b; /* bg-slate-900 */
289
+ padding: 0.5rem;
290
+ color: #cbd5e1; /* text-slate-500 */
291
+ margin-bottom: 20px;
292
+ }
293
+
294
+ .custom-card-header {
295
+ position: relative;
296
+ display: flex;
297
+ justify-content: center;
298
+ align-items: center;
299
+ text-align: center;
300
+ font-size: 0.75rem; /* text-xs */
301
+ color: #cbd5e1; /* text-slate-500 */
302
+ }
303
+
304
+ .icon-group {
305
+ display: flex;
306
+ padding-left: 0.875rem; /* pl-3.5 */
307
+ padding-top: 0.75rem; /* pt-3 */
308
+ }
309
+
310
+ .icon {
311
+ margin-left: -0.125rem; /* -ml-0.5 */
312
+ margin-right: 0.375rem; /* mr-1.5 */
313
+ height: 0.75rem; /* h-3 */
314
+ width: 0.75rem; /* w-3 */
315
+ }
316
+
317
+ .icon.red {
318
+ color: rgba(239, 68, 68, 0.2); /* text-red-500/20 */
319
+ }
320
+
321
+ .icon.yellow {
322
+ color: rgba(234, 179, 8, 0.2); /* text-yellow-500/20 */
323
+ }
324
+
325
+ .icon.green {
326
+ color: rgba(34, 197, 94, 0.2); /* text-green-500/20 */
327
+ }
328
+
329
+ .file-name {
330
+ position: absolute;
331
+ top: 0.5rem; /* top-2 */
332
+ left: 0;
333
+ right: 0;
334
+ font-size: 0.75rem; /* text-xs */
335
+ color: #94a3b8; /* text-slate-500 */
336
+ }
337
+
338
+ .custom-card-body {
339
+ margin-top: 1.25rem; /* mt-5 */
340
+ padding-left: 1.25rem; /* px-5 */
341
+ padding-bottom: 2.5rem; /* pb-10 */
342
+ /* space-y-1.5 nie jest bezpośrednio wspierane w CSS, użyj odstępów między elementami */
343
+ }
344
+
345
+ .code-line {
346
+ font-family: monospace;
347
+ font-size: 0.75rem; /* text-xs */
348
+ font-weight: normal;
349
+ letter-spacing: 0.05em; /* tracking-wide */
350
+ color: #a78bfa; /* text-violet-400 */
351
+ margin-top: 1rem; /* mt-4 dla pierwszej linii, dostosuj w razie potrzeby */
352
+ }
353
+
354
+ .text-slate {
355
+ color: #64748b; /* text-slate-500 */
356
+ }
357
+
358
+ .text-pink {
359
+ color: #ec4899; /* text-pink-400 */
360
+ }
361
+
362
+ .highlight {
363
+ position: relative;
364
+ display: inline-block;
365
+ padding-left: 0.25rem; /* px-1 */
366
+ padding-right: 0.25rem;
367
+ background-color: rgba(59, 130, 246, 0.1); /* bg-blue-500/10 */
368
+ color: #60a5fa; /* text-blue-400 */
369
+ }
370
+
371
+ .text-blue {
372
+ color: #60a5fa; /* text-blue-400 */
373
+ }
374
  """
375
 
376
  # Tworzenie interfejsu Gradio z niestandardowym CSS
377
  with gr.Blocks(css=custom_css) as demo:
378
+ # Nagłówek "Cards"
379
+ gr.HTML("""
380
+ <div class="custom-card">
381
+ <div class="custom-card-header">
382
+ <div class="icon-group">
383
+ <svg viewBox="0 0 24 24" fill="currentColor" class="icon red">
384
+ <circle r="12" cy="12" cx="12"></circle>
385
+ </svg>
386
+ <svg viewBox="0 0 24 24" fill="currentColor" class="icon yellow">
387
+ <circle r="12" cy="12" cx="12"></circle>
388
+ </svg>
389
+ <svg viewBox="0 0 24 24" fill="currentColor" class="icon green">
390
+ <circle r="12" cy="12" cx="12"></circle>
391
+ </svg>
392
+ </div>
393
+ <span class="file-name">ProgressBar.tsx</span>
394
+ </div>
395
+ <div class="custom-card-body">
396
+ <p class="code-line">
397
+ <span class="text-slate">&lt;</span><span class="text-pink">Card</span><span class="text-slate">&gt;</span>
398
+ </p>
399
+ <p class="code-line">
400
+ <span class="text-slate">&lt;</span><span class="text-pink">Text</span><span class="text-slate">&gt;</span><span class="highlight">Ticket Sales</span><span class="text-slate">&lt;/</span><span class="text-pink">Text</span><span class="text-slate">&gt;</span>
401
+ </p>
402
+ <p class="code-line">
403
+ <span class="text-slate">&lt;</span><span class="text-pink">Metric</span><span class="text-slate">&gt;</span><span class="highlight">$ 71,465</span><span class="text-slate">&lt;/</span><span class="text-pink">Metric</span><span class="text-slate">&gt;</span>
404
+ </p>
405
+ <p class="code-line">
406
+ <span class="text-slate">&lt;</span><span class="text-pink">Flex</span><span class="text-slate"> className=</span><span class="highlight">"mt-3"</span><span class="text-slate">&gt;</span>
407
+ </p>
408
+ <p class="code-line" style="margin-left: 1.5rem;">
409
+ <span class="text-slate">&lt;</span><span class="text-pink">Text</span><span class="text-slate">&gt;</span><span class="text-slate">&lt;</span><span class="text-pink">Bold</span><span class="text-slate">&gt;</span><span class="highlight">32%</span><span class="text-slate">&lt;/</span><span class="text-pink">Bold</span><span class="text-slate">&gt;</span><span class="highlight"> of annual target</span><span class="text-slate">&lt;/</span><span class="text-pink">Text</span><span class="text-slate">&gt;</span>
410
+ </p>
411
+ <p class="code-line" style="margin-left: 1.5rem;">
412
+ <span class="text-slate">&lt;</span><span class="text-pink">Text</span><span class="text-slate">&gt;</span><span class="highlight">$ 223,328</span><span class="text-slate">&lt;/</span><span class="text-pink">Text</span><span class="text-slate">&gt;</span>
413
+ </p>
414
+ <p class="code-line">
415
+ <span class="text-slate">&lt;/</span><span class="text-pink">Flex</span><span class="text-slate">&gt;</span>
416
+ </p>
417
+ <p class="code-line">
418
+ <span class="text-slate">&lt;</span><span class="text-pink">ProgressBar</span><span class="text-slate"> value=</span><span class="highlight">{ 32 }</span><span class="text-slate"> className=</span><span class="highlight">"mt-3"</span><span class="text-slate">/&gt;</span>
419
+ </p>
420
+ <p class="code-line">
421
+ <span class="text-slate">&lt;/</span><span class="text-pink">Card</span><span class="text-slate">&gt;</span>
422
+ </p>
423
+ </div>
424
+ </div>
425
+ """)
426
+
427
+ # Nagłówek główny
428
  gr.Markdown("# 🧠 **D-LOGIC: Twój Inteligentny Asystent AI**")
429
+
430
+ # Opis narzędzia
431
  gr.Markdown("""
432
  **D-LOGIC** to zaawansowany asystent AI stworzony przez Rafała Dembskiego. Dzięki zaawansowanemu procesowi myślowemu, **D-LOGIC** analizuje, planuje i dostarcza precyzyjne odpowiedzi na Twoje pytania, zapewniając jednocześnie interaktywną i angażującą konwersację.
433
 
 
437
  - **Generowanie Rozwiązań**: Proponowanie najlepszych możliwych odpowiedzi.
438
  - **Refleksja**: Samoocena jakości odpowiedzi i procesów myślowych.
439
  """)
440
+
441
  # Wybór modelu i budżet myślenia
442
  with gr.Row():
443
  with gr.Column(scale=1):
 
456
  label="🧩 Budżet Myślenia",
457
  info="Maksymalna liczba kroków, które model może przemyśleć"
458
  )
459
+
460
  # Sekcja czatu
461
  chatbot = gr.Chatbot(
462
  label="💬 Chat",
 
467
  layout="vertical",
468
  height=600
469
  )
470
+
471
  # Pole do wpisywania wiadomości
472
  with gr.Row():
473
  msg = gr.Textbox(
 
475
  placeholder="Wprowadź swoją wiadomość...",
476
  lines=1
477
  )
478
+
479
  # Przycisk Wyślij i Wyczyść
480
  with gr.Row():
481
  submit_button = gr.Button("🚀 Wyślij", variant="primary")
482
  clear_button = gr.Button("🧹 Wyczyść Chat", variant="secondary")
483
+
484
  # Panel Informacyjny
485
  info_panel = gr.Markdown(
486
  value="**Informacje:**\nCzas myślenia i inne dane będą tutaj wyświetlane.",
487
  elem_id="info-panel"
488
  )
489
+
490
  # Akcje przycisków
491
  clear_button.click(
492
  fn=lambda: ([], "", "**Informacje:**\nCzas myślenia i inne dane zostały zresetowane."),
493
  inputs=None,
494
  outputs=[chatbot, msg, info_panel]
495
  )
496
+
497
  # Przesyłanie wiadomości poprzez Enter lub kliknięcie przycisku Wyślij
498
  msg.submit(
499
  fn=generate,
500
+ inputs=[msg, chatbot, model, thinking_budget, gr.State()],
501
  outputs=[chatbot, msg, info_panel]
502
  )
503
  submit_button.click(
504
  fn=generate,
505
+ inputs=[msg, chatbot, model, thinking_budget, gr.State()],
506
  outputs=[chatbot, msg, info_panel]
507
  )
508
+
 
 
509
  # Uruchomienie aplikacji Gradio na Hugging Face Spaces
510
  demo.launch(share=False, show_api=False)