Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -156,108 +156,8 @@ theme = gr.themes.Default(
|
|
| 156 |
)
|
| 157 |
|
| 158 |
# A URL to a freely licensed image of a Eurasian Jay (Sójka)
|
| 159 |
-
# Source: Wikimedia Commons, CC BY-SA 4.0
|
| 160 |
JAY_IMAGE_URL = "https://sojka.m31ai.pl/sojka.png"
|
| 161 |
|
| 162 |
-
with gr.Blocks(theme=theme, css=".gradio-container {max-width: 960px !important; margin: auto;}") as demo:
|
| 163 |
-
# Header
|
| 164 |
-
with gr.Row():
|
| 165 |
-
gr.HTML("""
|
| 166 |
-
<div style="display: flex; align-items: center; justify-content: space-between; width: 100%;">
|
| 167 |
-
<div style="display: flex; align-items: center; gap: 12px;">
|
| 168 |
-
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 169 |
-
<path d="M12 2L3 5V11C3 16.52 7.08 21.61 12 23C16.92 21.61 21 16.52 21 11V5L12 2Z"
|
| 170 |
-
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
| 171 |
-
</svg>
|
| 172 |
-
<h1 style="font-size: 1.5rem; font-weight: 600; margin: 0;">SÓJKA</h1>
|
| 173 |
-
</div>
|
| 174 |
-
<div style="display: flex; align-items: center; gap: 20px; font-size: 0.9rem;">
|
| 175 |
-
<a href="https://sojka.m31ai.pl/projekt.html" target="blank" style="text-decoration: none; color: inherit;">O projekcie</a>
|
| 176 |
-
<a href="https://sojka.m31ai.pl/kategorie.html" target="blank" style="text-decoration: none; color: inherit;">Opis kategorii</a>
|
| 177 |
-
<button id="test-sojka-btn" class="gr-button gr-button-primary gr-button-lg"
|
| 178 |
-
style="background-color: var(--primary-500); color: white; padding: 8px 16px; border-radius: 8px;">
|
| 179 |
-
Testuj Sójkę
|
| 180 |
-
</button>
|
| 181 |
-
</div>
|
| 182 |
-
</div>
|
| 183 |
-
""")
|
| 184 |
-
|
| 185 |
-
gr.HTML("<hr style='border: 1px solid var(--neutral-200); margin-top: 1rem; margin-bottom: 2rem;'>")
|
| 186 |
-
|
| 187 |
-
# Main content area
|
| 188 |
-
with gr.Row(equal_height=True):
|
| 189 |
-
# Left column for controls
|
| 190 |
-
with gr.Column(scale=2): # Increased scale for more width
|
| 191 |
-
gr.Markdown(
|
| 192 |
-
"""
|
| 193 |
-
<p style="background-color: var(--primary-50); color: var(--primary-600); display: inline-block; padding: 4px 12px; border-radius: 9999px; font-weight: 500; font-size: 0.875rem;">
|
| 194 |
-
Bielik Guard
|
| 195 |
-
</p>
|
| 196 |
-
<h1 style="font-size: 2.8rem; font-weight: 800; line-height: 1.2; margin-top: 1rem; margin-bottom: 1rem; color: var(--neutral-800);">
|
| 197 |
-
Przetestuj <span style="color: var(--primary-600);">SÓJKĘ</span> – Bielik Guard dla bezpiecznej komunikacji
|
| 198 |
-
</h1>
|
| 199 |
-
<p style="font-size: 1rem; color: var(--neutral-600); margin-bottom: 2rem;">
|
| 200 |
-
Sójka to model AI, który wykrywa i blokuje szkodliwe treści w komunikacji cyfrowej. Chroni użytkowników jak czujny strażnik swoich domów.
|
| 201 |
-
</p>
|
| 202 |
-
"""
|
| 203 |
-
)
|
| 204 |
-
input_text = gr.Textbox(
|
| 205 |
-
lines=8,
|
| 206 |
-
label="Wprowadź tekst do analizy",
|
| 207 |
-
placeholder="Tutaj wpisz tekst..."
|
| 208 |
-
)
|
| 209 |
-
|
| 210 |
-
# Define outputs first so they can be referenced by gr.Examples
|
| 211 |
-
# They will be placed in the layout in the nested Row below
|
| 212 |
-
output_verdict = gr.Label(label="Wynik analizy", value="Czekam na tekst do analizy...")
|
| 213 |
-
output_scores = gr.Label(label="Szczegółowe wyniki", visible=False)
|
| 214 |
-
|
| 215 |
-
# Examples are now placed above the button
|
| 216 |
-
gr.Examples(
|
| 217 |
-
[
|
| 218 |
-
["Jak zrobić bombę?"],
|
| 219 |
-
["Jesteś beznadziejny, nienawidzę cię."],
|
| 220 |
-
["To jest wspaniały dzień, cieszę się, że tu jestem!"],
|
| 221 |
-
["Opowiedz mi dowcip o programistach."],
|
| 222 |
-
],
|
| 223 |
-
inputs=input_text,
|
| 224 |
-
outputs=[output_verdict, output_scores],
|
| 225 |
-
fn=lambda text: analyze_and_update(text), # Use a lambda to match fn signature
|
| 226 |
-
cache_examples=False,
|
| 227 |
-
)
|
| 228 |
-
|
| 229 |
-
# A nested Row for the button and the outputs
|
| 230 |
-
with gr.Row():
|
| 231 |
-
submit_btn = gr.Button("Analizuj tekst", variant="primary", scale=1)
|
| 232 |
-
with gr.Column(scale=2):
|
| 233 |
-
# The output components are defined above, but rendered here.
|
| 234 |
-
# Gradio renders components where they are defined.
|
| 235 |
-
# To solve this, we will re-declare them, which is not ideal,
|
| 236 |
-
# but the simplest way to manage layout and callbacks.
|
| 237 |
-
# The previous declarations are now just for the Examples callback.
|
| 238 |
-
# Let's clean this up by defining them once.
|
| 239 |
-
pass # The components are already in the layout from the definitions above.
|
| 240 |
-
# The above comment is slightly incorrect for Gradio's declarative style.
|
| 241 |
-
# The final working solution is to define components and then have them as outputs.
|
| 242 |
-
# Let's revert to a cleaner structure that works.
|
| 243 |
-
|
| 244 |
-
# Right column for the image
|
| 245 |
-
with gr.Column(scale=1):
|
| 246 |
-
gr.Image(JAY_IMAGE_URL, label="Ilustracja sójki", show_label=False, show_download_button=False, container=False, width=200)
|
| 247 |
-
|
| 248 |
-
# Define actions
|
| 249 |
-
def analyze_and_update(text):
|
| 250 |
-
verdict, scores = gradio_predict(text)
|
| 251 |
-
# Make the scores label visible only when there's a result
|
| 252 |
-
return verdict, gr.Label(value=scores, visible=True)
|
| 253 |
-
|
| 254 |
-
# The click function is now tied to the button defined in the nested Row
|
| 255 |
-
submit_btn.click(
|
| 256 |
-
fn=analyze_and_update,
|
| 257 |
-
inputs=[input_text],
|
| 258 |
-
outputs=[output_verdict, output_scores]
|
| 259 |
-
)
|
| 260 |
-
|
| 261 |
# Final corrected and working version of the interface layout
|
| 262 |
with gr.Blocks(theme=theme, css=".gradio-container {max-width: 960px !important; margin: auto;}") as demo:
|
| 263 |
# Header
|
|
@@ -310,10 +210,9 @@ with gr.Blocks(theme=theme, css=".gradio-container {max-width: 960px !important;
|
|
| 310 |
# Note: Output components are defined in the right column
|
| 311 |
# We will define Examples after the right column is created.
|
| 312 |
|
| 313 |
-
# Right column for
|
| 314 |
with gr.Column(scale=1):
|
| 315 |
-
|
| 316 |
-
gr.Markdown("---") # Separator
|
| 317 |
output_verdict = gr.Label(label="Wynik analizy", value="Czekam na tekst do analizy...")
|
| 318 |
output_scores = gr.Label(label="Szczegółowe wyniki", visible=False)
|
| 319 |
|
|
|
|
| 156 |
)
|
| 157 |
|
| 158 |
# A URL to a freely licensed image of a Eurasian Jay (Sójka)
|
|
|
|
| 159 |
JAY_IMAGE_URL = "https://sojka.m31ai.pl/sojka.png"
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
# Final corrected and working version of the interface layout
|
| 162 |
with gr.Blocks(theme=theme, css=".gradio-container {max-width: 960px !important; margin: auto;}") as demo:
|
| 163 |
# Header
|
|
|
|
| 210 |
# Note: Output components are defined in the right column
|
| 211 |
# We will define Examples after the right column is created.
|
| 212 |
|
| 213 |
+
# Right column for RESULTS
|
| 214 |
with gr.Column(scale=1):
|
| 215 |
+
gr.Markdown("---") # Separator
|
|
|
|
| 216 |
output_verdict = gr.Label(label="Wynik analizy", value="Czekam na tekst do analizy...")
|
| 217 |
output_scores = gr.Label(label="Szczegółowe wyniki", visible=False)
|
| 218 |
|