rafaldembski
commited on
Commit
•
9ba9367
1
Parent(s):
d3b9619
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import openai
|
|
3 |
import time
|
4 |
import re
|
5 |
import os
|
|
|
6 |
|
7 |
# Dostępne modele
|
8 |
MODELS = [
|
@@ -64,26 +65,32 @@ def generate(message, history, model, thinking_budget, api_key=None):
|
|
64 |
"""Generuje odpowiedź chatbota."""
|
65 |
system_prompt = DEFAULT_SYSTEM_PROMPT
|
66 |
|
67 |
-
|
68 |
-
chat_history = []
|
69 |
-
for user_msg, assistant_msg in history:
|
70 |
-
chat_history.append({"role": "user", "content": user_msg})
|
71 |
-
chat_history.append({"role": "assistant", "content": assistant_msg})
|
72 |
-
|
73 |
-
response, thinking_time = respond(message, chat_history, model, system_prompt, thinking_budget, api_key)
|
74 |
|
75 |
if response.startswith("Error:"):
|
76 |
assistant_response = response
|
|
|
|
|
77 |
else:
|
78 |
answer, reflection, steps = parse_response(response)
|
79 |
-
|
80 |
# Budowanie odpowiedzi asystenta
|
81 |
formatted_steps = [f"**Krok {i}:** {step}" for i, step in enumerate(steps, 1)]
|
82 |
all_steps = "\n".join(formatted_steps) + f"\n\n**Refleksja:** {reflection}"
|
83 |
assistant_response = f"{all_steps}\n\n{answer}"
|
84 |
|
85 |
-
#
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
# Definiowanie domyślnego system prompt
|
89 |
DEFAULT_SYSTEM_PROMPT = """
|
@@ -177,7 +184,7 @@ h2, .gr-markdown h2 {
|
|
177 |
}
|
178 |
|
179 |
/* Karty i panele */
|
180 |
-
#component-0, #component-1, #component-2, #component-3 {
|
181 |
background-color: #ffffff;
|
182 |
border-radius: 12px;
|
183 |
padding: 20px;
|
@@ -249,6 +256,16 @@ textarea:focus {
|
|
249 |
margin-top: 20px;
|
250 |
font-size: 14px;
|
251 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
"""
|
253 |
|
254 |
# Tworzenie interfejsu Gradio z niestandardowym CSS
|
@@ -302,23 +319,29 @@ with gr.Blocks(css=custom_css) as demo:
|
|
302 |
submit_button = gr.Button("🚀 **Wyślij**", variant="primary")
|
303 |
clear_button = gr.Button("🧹 **Wyczyść Chat**", variant="secondary")
|
304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
# Akcje przycisków
|
306 |
clear_button.click(
|
307 |
-
fn=lambda: ([], ""),
|
308 |
inputs=None,
|
309 |
-
outputs=[chatbot, msg]
|
310 |
)
|
311 |
|
312 |
# Przesyłanie wiadomości poprzez Enter lub kliknięcie przycisku Wyślij
|
313 |
msg.submit(
|
314 |
fn=generate,
|
315 |
inputs=[msg, chatbot, model, thinking_budget],
|
316 |
-
outputs=[chatbot, msg]
|
317 |
)
|
318 |
submit_button.click(
|
319 |
fn=generate,
|
320 |
inputs=[msg, chatbot, model, thinking_budget],
|
321 |
-
outputs=[chatbot, msg]
|
322 |
)
|
323 |
|
324 |
# Stopka
|
|
|
3 |
import time
|
4 |
import re
|
5 |
import os
|
6 |
+
from datetime import datetime
|
7 |
|
8 |
# Dostępne modele
|
9 |
MODELS = [
|
|
|
65 |
"""Generuje odpowiedź chatbota."""
|
66 |
system_prompt = DEFAULT_SYSTEM_PROMPT
|
67 |
|
68 |
+
response, thinking_time = respond(message, history, model, system_prompt, thinking_budget, api_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
if response.startswith("Error:"):
|
71 |
assistant_response = response
|
72 |
+
steps = []
|
73 |
+
reflection = ""
|
74 |
else:
|
75 |
answer, reflection, steps = parse_response(response)
|
|
|
76 |
# Budowanie odpowiedzi asystenta
|
77 |
formatted_steps = [f"**Krok {i}:** {step}" for i, step in enumerate(steps, 1)]
|
78 |
all_steps = "\n".join(formatted_steps) + f"\n\n**Refleksja:** {reflection}"
|
79 |
assistant_response = f"{all_steps}\n\n{answer}"
|
80 |
|
81 |
+
# Aktualizacja historii jako lista krotek
|
82 |
+
updated_history = history + [(message, assistant_response)]
|
83 |
+
|
84 |
+
# Przygotowanie informacji do wyświetlenia
|
85 |
+
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
86 |
+
info_text = f"""
|
87 |
+
**Czas Myślenia:** {thinking_time:.2f} sek<br>
|
88 |
+
**Wybrany Model:** {model}<br>
|
89 |
+
**Liczba Kroków:** {len(steps)}<br>
|
90 |
+
**Data i Czas Odpowiedzi:** {current_time}
|
91 |
+
"""
|
92 |
+
|
93 |
+
return updated_history, "", info_text
|
94 |
|
95 |
# Definiowanie domyślnego system prompt
|
96 |
DEFAULT_SYSTEM_PROMPT = """
|
|
|
184 |
}
|
185 |
|
186 |
/* Karty i panele */
|
187 |
+
#component-0, #component-1, #component-2, #component-3, #component-4 {
|
188 |
background-color: #ffffff;
|
189 |
border-radius: 12px;
|
190 |
padding: 20px;
|
|
|
256 |
margin-top: 20px;
|
257 |
font-size: 14px;
|
258 |
}
|
259 |
+
|
260 |
+
/* Panel Informacyjny */
|
261 |
+
.info-panel {
|
262 |
+
background-color: #f9fafb;
|
263 |
+
border: 1px solid #dcdcdc;
|
264 |
+
border-radius: 8px;
|
265 |
+
padding: 15px;
|
266 |
+
font-size: 14px;
|
267 |
+
color: #333333;
|
268 |
+
}
|
269 |
"""
|
270 |
|
271 |
# Tworzenie interfejsu Gradio z niestandardowym CSS
|
|
|
319 |
submit_button = gr.Button("🚀 **Wyślij**", variant="primary")
|
320 |
clear_button = gr.Button("🧹 **Wyczyść Chat**", variant="secondary")
|
321 |
|
322 |
+
# Panel Informacyjny
|
323 |
+
info_panel = gr.Markdown(
|
324 |
+
value="**Informacje:**\nCzas myślenia i inne dane będą tutaj wyświetlane.",
|
325 |
+
elem_id="info-panel"
|
326 |
+
)
|
327 |
+
|
328 |
# Akcje przycisków
|
329 |
clear_button.click(
|
330 |
+
fn=lambda: ([], "", "Informacje zostaną zresetowane."),
|
331 |
inputs=None,
|
332 |
+
outputs=[chatbot, msg, info_panel]
|
333 |
)
|
334 |
|
335 |
# Przesyłanie wiadomości poprzez Enter lub kliknięcie przycisku Wyślij
|
336 |
msg.submit(
|
337 |
fn=generate,
|
338 |
inputs=[msg, chatbot, model, thinking_budget],
|
339 |
+
outputs=[chatbot, msg, info_panel]
|
340 |
)
|
341 |
submit_button.click(
|
342 |
fn=generate,
|
343 |
inputs=[msg, chatbot, model, thinking_budget],
|
344 |
+
outputs=[chatbot, msg, info_panel]
|
345 |
)
|
346 |
|
347 |
# Stopka
|