Jacek Zadrożny
commited on
Commit
·
3a40a92
1
Parent(s):
f509ce1
Naprawiony format wymiany z chatem
Browse files
app.py
CHANGED
|
@@ -138,7 +138,8 @@ with gr.Blocks(title="A11y Expert") as demo:
|
|
| 138 |
msg = gr.Textbox(
|
| 139 |
placeholder="Zadaj pytanie o WCAG, ARIA, lub poproś o analizę kodu...",
|
| 140 |
show_label=False,
|
| 141 |
-
container=False
|
|
|
|
| 142 |
)
|
| 143 |
|
| 144 |
with gr.Row():
|
|
@@ -195,15 +196,21 @@ Stwórz plik `notes.md` w katalogu projektu aby zobaczyć tutaj swoje notatki.
|
|
| 195 |
# Chat logic
|
| 196 |
def user_message(user_input, history):
|
| 197 |
"""Add user message to chat history."""
|
| 198 |
-
return "", history + [
|
| 199 |
|
| 200 |
def bot_response(history):
|
| 201 |
"""Generate bot response."""
|
| 202 |
-
user_input = history[-1][
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
for response in respond(user_input, history[:-1]):
|
| 206 |
-
history[-1][
|
| 207 |
yield history
|
| 208 |
|
| 209 |
# Wire up the chat
|
|
|
|
| 138 |
msg = gr.Textbox(
|
| 139 |
placeholder="Zadaj pytanie o WCAG, ARIA, lub poproś o analizę kodu...",
|
| 140 |
show_label=False,
|
| 141 |
+
container=False,
|
| 142 |
+
max_length=300
|
| 143 |
)
|
| 144 |
|
| 145 |
with gr.Row():
|
|
|
|
| 196 |
# Chat logic
|
| 197 |
def user_message(user_input, history):
|
| 198 |
"""Add user message to chat history."""
|
| 199 |
+
return "", history + [{"role": "user", "content": user_input}]
|
| 200 |
|
| 201 |
def bot_response(history):
|
| 202 |
"""Generate bot response."""
|
| 203 |
+
user_input = history[-1]["content"]
|
| 204 |
+
|
| 205 |
+
# Extract text from multimodal format if needed
|
| 206 |
+
if isinstance(user_input, list):
|
| 207 |
+
user_input = " ".join([item.get("text", "") for item in user_input if item.get("type") == "text"])
|
| 208 |
+
|
| 209 |
+
# Add assistant message placeholder
|
| 210 |
+
history.append({"role": "assistant", "content": ""})
|
| 211 |
|
| 212 |
for response in respond(user_input, history[:-1]):
|
| 213 |
+
history[-1]["content"] = response
|
| 214 |
yield history
|
| 215 |
|
| 216 |
# Wire up the chat
|