Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -187,7 +187,7 @@ with gr.Blocks(theme=theme, css=".gradio-container {max-width: 960px !important;
|
|
187 |
# Main content area
|
188 |
with gr.Row(equal_height=True):
|
189 |
# Left column for controls
|
190 |
-
with gr.Column(scale=
|
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;">
|
@@ -206,14 +206,44 @@ with gr.Blocks(theme=theme, css=".gradio-container {max-width: 960px !important;
|
|
206 |
label="Wprowadź tekst do analizy",
|
207 |
placeholder="Tutaj wpisz tekst..."
|
208 |
)
|
209 |
-
|
210 |
-
|
|
|
211 |
output_verdict = gr.Label(label="Wynik analizy", value="Czekam na tekst do analizy...")
|
212 |
output_scores = gr.Label(label="Szczegółowe wyniki", visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
# Right column for the image
|
215 |
with gr.Column(scale=1):
|
216 |
-
gr.Image(JAY_IMAGE_URL, label="Ilustracja sójki", show_label=False, show_download_button=False, container=False)
|
217 |
|
218 |
# Define actions
|
219 |
def analyze_and_update(text):
|
@@ -221,12 +251,74 @@ with gr.Blocks(theme=theme, css=".gradio-container {max-width: 960px !important;
|
|
221 |
# Make the scores label visible only when there's a result
|
222 |
return verdict, gr.Label(value=scores, visible=True)
|
223 |
|
|
|
224 |
submit_btn.click(
|
225 |
fn=analyze_and_update,
|
226 |
inputs=[input_text],
|
227 |
outputs=[output_verdict, output_scores]
|
228 |
)
|
229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
gr.Examples(
|
231 |
[
|
232 |
["Jak zrobić bombę?"],
|
@@ -239,9 +331,24 @@ with gr.Blocks(theme=theme, css=".gradio-container {max-width: 960px !important;
|
|
239 |
fn=analyze_and_update,
|
240 |
cache_examples=False,
|
241 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
if __name__ == "__main__":
|
244 |
if not model_loaded:
|
245 |
print("Aplikacja nie może zostać uruchomiona, ponieważ nie udało się załadować modelu. Sprawdź logi błędów.")
|
246 |
else:
|
|
|
247 |
demo.launch()
|
|
|
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;">
|
|
|
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):
|
|
|
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
|
264 |
+
with gr.Row():
|
265 |
+
gr.HTML("""
|
266 |
+
<div style="display: flex; align-items: center; justify-content: space-between; width: 100%;">
|
267 |
+
<div style="display: flex; align-items: center; gap: 12px;">
|
268 |
+
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
269 |
+
<path d="M12 2L3 5V11C3 16.52 7.08 21.61 12 23C16.92 21.61 21 16.52 21 11V5L12 2Z"
|
270 |
+
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
271 |
+
</svg>
|
272 |
+
<h1 style="font-size: 1.5rem; font-weight: 600; margin: 0;">SÓJKA</h1>
|
273 |
+
</div>
|
274 |
+
<div style="display: flex; align-items: center; gap: 20px; font-size: 0.9rem;">
|
275 |
+
<a href="https://sojka.m31ai.pl/projekt.html" target="blank" style="text-decoration: none; color: inherit;">O projekcie</a>
|
276 |
+
<a href="https://sojka.m31ai.pl/kategorie.html" target="blank" style="text-decoration: none; color: inherit;">Opis kategorii</a>
|
277 |
+
<button id="test-sojka-btn" class="gr-button gr-button-primary gr-button-lg"
|
278 |
+
style="background-color: var(--primary-500); color: white; padding: 8px 16px; border-radius: 8px;">
|
279 |
+
Testuj Sójkę
|
280 |
+
</button>
|
281 |
+
</div>
|
282 |
+
</div>
|
283 |
+
""")
|
284 |
+
|
285 |
+
gr.HTML("<hr style='border: 1px solid var(--neutral-200); margin-top: 1rem; margin-bottom: 2rem;'>")
|
286 |
+
|
287 |
+
# Main content area
|
288 |
+
with gr.Row():
|
289 |
+
# Left column for controls and description
|
290 |
+
with gr.Column(scale=2):
|
291 |
+
gr.Markdown(
|
292 |
+
"""
|
293 |
+
<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;">
|
294 |
+
Bielik Guard
|
295 |
+
</p>
|
296 |
+
<h1 style="font-size: 2.8rem; font-weight: 800; line-height: 1.2; margin-top: 1rem; margin-bottom: 1rem; color: var(--neutral-800);">
|
297 |
+
Przetestuj <span style="color: var(--primary-600);">SÓJKĘ</span> – Bielik Guard dla bezpiecznej komunikacji
|
298 |
+
</h1>
|
299 |
+
<p style="font-size: 1rem; color: var(--neutral-600); margin-bottom: 2rem;">
|
300 |
+
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.
|
301 |
+
</p>
|
302 |
+
"""
|
303 |
+
)
|
304 |
+
input_text = gr.Textbox(
|
305 |
+
lines=8,
|
306 |
+
label="Wprowadź tekst do analizy",
|
307 |
+
placeholder="Tutaj wpisz tekst..."
|
308 |
+
)
|
309 |
+
|
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 the image and RESULTS
|
314 |
+
with gr.Column(scale=1):
|
315 |
+
gr.Image(JAY_IMAGE_URL, label="Ilustracja sójki", show_label=False, show_download_button=False, container=False, width=200)
|
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 |
+
|
320 |
+
# Interactive elements are defined last, after all components are created
|
321 |
+
# This places the examples above the button
|
322 |
gr.Examples(
|
323 |
[
|
324 |
["Jak zrobić bombę?"],
|
|
|
331 |
fn=analyze_and_update,
|
332 |
cache_examples=False,
|
333 |
)
|
334 |
+
|
335 |
+
submit_btn = gr.Button("Analizuj tekst", variant="primary")
|
336 |
+
|
337 |
+
# Define actions
|
338 |
+
def analyze_and_update(text):
|
339 |
+
verdict, scores = gradio_predict(text)
|
340 |
+
return verdict, gr.update(value=scores, visible=True)
|
341 |
+
|
342 |
+
submit_btn.click(
|
343 |
+
fn=analyze_and_update,
|
344 |
+
inputs=[input_text],
|
345 |
+
outputs=[output_verdict, output_scores]
|
346 |
+
)
|
347 |
+
|
348 |
|
349 |
if __name__ == "__main__":
|
350 |
if not model_loaded:
|
351 |
print("Aplikacja nie może zostać uruchomiona, ponieważ nie udało się załadować modelu. Sprawdź logi błędów.")
|
352 |
else:
|
353 |
+
# The final, corrected demo object is launched
|
354 |
demo.launch()
|