Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
"""
|
| 4 |
-
Gradio App - Intelligent Stacking Classifier (Dark Mode
|
| 5 |
"""
|
| 6 |
import gradio as gr
|
| 7 |
import numpy as np
|
| 8 |
import joblib
|
| 9 |
import re
|
| 10 |
from pathlib import Path
|
| 11 |
-
from time import sleep # para simular loading (se necessário)
|
| 12 |
|
| 13 |
# Sklearn
|
| 14 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
@@ -135,9 +134,7 @@ class PortugueseClassifier:
|
|
| 135 |
classifier = PortugueseClassifier()
|
| 136 |
|
| 137 |
|
| 138 |
-
def
|
| 139 |
-
"""Simula loading, depois retorna cards"""
|
| 140 |
-
sleep(0.5) # delay curto para efeito visual de loading
|
| 141 |
preds = classifier.predict(text)
|
| 142 |
cards = ""
|
| 143 |
for p in preds[:10]:
|
|
@@ -149,21 +146,20 @@ def classify_text_with_loading(text):
|
|
| 149 |
|
| 150 |
cards += f"""
|
| 151 |
<div style="
|
| 152 |
-
border-left:
|
| 153 |
background-color:#1E1E1E;
|
| 154 |
-
padding:
|
| 155 |
-
margin-bottom:
|
| 156 |
-
border-radius:
|
| 157 |
-
transition: transform 0.2s;
|
| 158 |
">
|
| 159 |
-
<strong style="color:#fff
|
| 160 |
<small style="color:#ccc">Probability: {prob:.1%}</small>
|
| 161 |
</div>
|
| 162 |
"""
|
| 163 |
return cards
|
| 164 |
|
| 165 |
|
| 166 |
-
#
|
| 167 |
css = """
|
| 168 |
body { background-color: #121212; color: #f5f5f5; font-family: 'Segoe UI', sans-serif; }
|
| 169 |
h1, h2, h3, h4 { color: #1E90FF; }
|
|
@@ -171,7 +167,6 @@ input, textarea { background-color: #1E1E1E; color: #f5f5f5; border: 1px solid #
|
|
| 171 |
button { background-color: #1E90FF; color: white; border-radius: 6px; border: none; }
|
| 172 |
.gradio-container { background-color: #121212; }
|
| 173 |
.output_html { background-color: #121212; color: #f5f5f5; }
|
| 174 |
-
.progress-bar { height: 4px; background-color:#1E90FF; width:0%; transition: width 0.5s; border-radius:2px; }
|
| 175 |
"""
|
| 176 |
|
| 177 |
with gr.Blocks(css=css, theme=None) as demo:
|
|
@@ -182,16 +177,9 @@ with gr.Blocks(css=css, theme=None) as demo:
|
|
| 182 |
text_input = gr.Textbox(label="Enter Portuguese administrative text", lines=10,
|
| 183 |
placeholder="Cole aqui o texto do documento...")
|
| 184 |
classify_btn = gr.Button("🔍 Classify")
|
| 185 |
-
progress = gr.HTML("<div class='progress-bar' id='loading-bar'></div>")
|
| 186 |
with gr.Column():
|
| 187 |
output = gr.HTML(label="Predicted Categories")
|
| 188 |
|
| 189 |
-
|
| 190 |
-
progress_bar = "<div class='progress-bar' style='width:100%'></div>"
|
| 191 |
-
# animação temporária
|
| 192 |
-
result = classify_text_with_loading(text)
|
| 193 |
-
return result
|
| 194 |
-
|
| 195 |
-
classify_btn.click(wrapped_click, inputs=text_input, outputs=output)
|
| 196 |
|
| 197 |
demo.launch()
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
"""
|
| 4 |
+
Gradio App - Intelligent Stacking Classifier (Dark Mode + Cards)
|
| 5 |
"""
|
| 6 |
import gradio as gr
|
| 7 |
import numpy as np
|
| 8 |
import joblib
|
| 9 |
import re
|
| 10 |
from pathlib import Path
|
|
|
|
| 11 |
|
| 12 |
# Sklearn
|
| 13 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
|
|
| 134 |
classifier = PortugueseClassifier()
|
| 135 |
|
| 136 |
|
| 137 |
+
def classify_text(text):
|
|
|
|
|
|
|
| 138 |
preds = classifier.predict(text)
|
| 139 |
cards = ""
|
| 140 |
for p in preds[:10]:
|
|
|
|
| 146 |
|
| 147 |
cards += f"""
|
| 148 |
<div style="
|
| 149 |
+
border-left: 5px solid {color};
|
| 150 |
background-color:#1E1E1E;
|
| 151 |
+
padding:10px;
|
| 152 |
+
margin-bottom:8px;
|
| 153 |
+
border-radius:6px;
|
|
|
|
| 154 |
">
|
| 155 |
+
<strong style="color:#fff">{label}</strong> {emoji}<br>
|
| 156 |
<small style="color:#ccc">Probability: {prob:.1%}</small>
|
| 157 |
</div>
|
| 158 |
"""
|
| 159 |
return cards
|
| 160 |
|
| 161 |
|
| 162 |
+
# Dark theme CSS
|
| 163 |
css = """
|
| 164 |
body { background-color: #121212; color: #f5f5f5; font-family: 'Segoe UI', sans-serif; }
|
| 165 |
h1, h2, h3, h4 { color: #1E90FF; }
|
|
|
|
| 167 |
button { background-color: #1E90FF; color: white; border-radius: 6px; border: none; }
|
| 168 |
.gradio-container { background-color: #121212; }
|
| 169 |
.output_html { background-color: #121212; color: #f5f5f5; }
|
|
|
|
| 170 |
"""
|
| 171 |
|
| 172 |
with gr.Blocks(css=css, theme=None) as demo:
|
|
|
|
| 177 |
text_input = gr.Textbox(label="Enter Portuguese administrative text", lines=10,
|
| 178 |
placeholder="Cole aqui o texto do documento...")
|
| 179 |
classify_btn = gr.Button("🔍 Classify")
|
|
|
|
| 180 |
with gr.Column():
|
| 181 |
output = gr.HTML(label="Predicted Categories")
|
| 182 |
|
| 183 |
+
classify_btn.click(classify_text, inputs=text_input, outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
demo.launch()
|