Jacek Zadrożny
commited on
Commit
·
af22390
1
Parent(s):
d05e81c
Add two-column layout with editable notes
Browse files- Left column: Chatbot interface
- Right column: Markdown notes loaded from notes.md
- Notes can be edited locally and pushed to update HF Spaces
- Refresh button to reload notes without restarting app
- Simpler than embedded editor - use your favorite text editor!
app.py
CHANGED
|
@@ -125,18 +125,95 @@ def respond(message: str, history: list[list[str]]):
|
|
| 125 |
|
| 126 |
|
| 127 |
# --- Gradio UI Definition ---
|
| 128 |
-
#
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
# --- App Launch ---
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
# --- Gradio UI Definition ---
|
| 128 |
+
# Two-column layout: Chat on left, Markdown content on right
|
| 129 |
+
with gr.Blocks(title="A11y Expert") as demo:
|
| 130 |
+
gr.Markdown("# 🤖 A11y Expert")
|
| 131 |
+
gr.Markdown("Twój inteligentny asystent do spraw dostępności cyfrowej.")
|
| 132 |
+
|
| 133 |
+
with gr.Row():
|
| 134 |
+
# Left column: Chatbot
|
| 135 |
+
with gr.Column(scale=1):
|
| 136 |
+
gr.Markdown("### 💬 Chat")
|
| 137 |
+
chatbot = gr.Chatbot(height=500, show_label=False)
|
| 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():
|
| 145 |
+
submit = gr.Button("Wyślij", variant="primary")
|
| 146 |
+
clear = gr.Button("Wyczyść")
|
| 147 |
+
|
| 148 |
+
# Example questions
|
| 149 |
+
gr.Examples(
|
| 150 |
+
examples=[
|
| 151 |
+
"Jakie są wymagania WCAG 2.2 dla etykiet formularzy?",
|
| 152 |
+
"Wyjaśnij rolę 'alert' w ARIA i podaj przykład.",
|
| 153 |
+
"Czy ten przycisk jest dostępny? <div onclick='...'>Click me</div>",
|
| 154 |
+
"Jaka jest różnica między aria-label a aria-labelledby?",
|
| 155 |
+
],
|
| 156 |
+
inputs=msg,
|
| 157 |
+
label="Przykładowe pytania"
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
# Right column: Markdown content from file
|
| 161 |
+
with gr.Column(scale=1):
|
| 162 |
+
gr.Markdown("### 📝 Notatki")
|
| 163 |
+
|
| 164 |
+
def load_notes():
|
| 165 |
+
"""Load notes from notes.md file."""
|
| 166 |
+
try:
|
| 167 |
+
with open("notes.md", "r", encoding="utf-8") as f:
|
| 168 |
+
return f.read()
|
| 169 |
+
except FileNotFoundError:
|
| 170 |
+
return """
|
| 171 |
+
## Witaj w A11y Expert! 👋
|
| 172 |
+
|
| 173 |
+
Stwórz plik `notes.md` w katalogu projektu aby zobaczyć tutaj swoje notatki.
|
| 174 |
+
|
| 175 |
+
### Przydatne linki:
|
| 176 |
+
- [WCAG 2.2 Guidelines](https://www.w3.org/WAI/WCAG22/quickref/)
|
| 177 |
+
- [ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/)
|
| 178 |
+
- [MDN Accessibility](https://developer.mozilla.org/en-US/docs/Web/Accessibility)
|
| 179 |
+
"""
|
| 180 |
+
except Exception as e:
|
| 181 |
+
return f"⚠️ Błąd wczytywania notes.md: {e}"
|
| 182 |
+
|
| 183 |
+
markdown_content = gr.Markdown(
|
| 184 |
+
value=load_notes(),
|
| 185 |
+
show_label=False,
|
| 186 |
+
elem_id="notes_display"
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
refresh_btn = gr.Button("🔄 Odśwież notatki", variant="secondary")
|
| 190 |
+
refresh_btn.click(
|
| 191 |
+
fn=load_notes,
|
| 192 |
+
outputs=markdown_content
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
# Chat logic
|
| 196 |
+
def user_message(user_input, history):
|
| 197 |
+
"""Add user message to chat history."""
|
| 198 |
+
return "", history + [[user_input, None]]
|
| 199 |
+
|
| 200 |
+
def bot_response(history):
|
| 201 |
+
"""Generate bot response."""
|
| 202 |
+
user_input = history[-1][0]
|
| 203 |
+
history[-1][1] = ""
|
| 204 |
+
|
| 205 |
+
for response in respond(user_input, history[:-1]):
|
| 206 |
+
history[-1][1] = response
|
| 207 |
+
yield history
|
| 208 |
+
|
| 209 |
+
# Wire up the chat
|
| 210 |
+
submit.click(user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 211 |
+
bot_response, chatbot, chatbot
|
| 212 |
+
)
|
| 213 |
+
msg.submit(user_message, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 214 |
+
bot_response, chatbot, chatbot
|
| 215 |
+
)
|
| 216 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 217 |
|
| 218 |
|
| 219 |
# --- App Launch ---
|
notes.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 📝 Moje Notatki o Dostępności
|
| 2 |
+
|
| 3 |
+
## Przydatne Linki
|
| 4 |
+
|
| 5 |
+
- [WCAG 2.2 Guidelines](https://www.w3.org/WAI/WCAG22/quickref/)
|
| 6 |
+
- [ARIA Authoring Practices Guide](https://www.w3.org/WAI/ARIA/apg/)
|
| 7 |
+
- [MDN Web Accessibility](https://developer.mozilla.org/en-US/docs/Web/Accessibility)
|
| 8 |
+
- [WebAIM Resources](https://webaim.org/resources/)
|
| 9 |
+
|
| 10 |
+
## Kluczowe Zasady WCAG
|
| 11 |
+
|
| 12 |
+
### Poziom A (Minimum)
|
| 13 |
+
- **1.1.1** - Alternatywa tekstowa dla treści nietekstowych
|
| 14 |
+
- **2.1.1** - Dostęp z klawiatury
|
| 15 |
+
- **3.1.1** - Język strony
|
| 16 |
+
|
| 17 |
+
### Poziom AA (Standardowy)
|
| 18 |
+
- **1.4.3** - Kontrast (minimum 4.5:1)
|
| 19 |
+
- **2.4.7** - Widoczny fokus
|
| 20 |
+
- **3.2.4** - Spójna identyfikacja
|
| 21 |
+
|
| 22 |
+
## Często Używane Role ARIA
|
| 23 |
+
|
| 24 |
+
```html
|
| 25 |
+
<!-- Navigation -->
|
| 26 |
+
<nav role="navigation" aria-label="Main menu">...</nav>
|
| 27 |
+
|
| 28 |
+
<!-- Alert -->
|
| 29 |
+
<div role="alert">Important message</div>
|
| 30 |
+
|
| 31 |
+
<!-- Button -->
|
| 32 |
+
<div role="button" tabindex="0" aria-pressed="false">Toggle</div>
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Moje Notatki
|
| 36 |
+
|
| 37 |
+
*Edytuj ten plik w swoim ulubionym edytorze i kliknij "🔄 Odśwież notatki" w aplikacji!*
|