Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,72 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Carga del modelo con autenticación automática usando token en entorno
|
| 5 |
classifier = pipeline(
|
| 6 |
"text-classification",
|
| 7 |
model="distilbert-base-uncased-finetuned-sst-2-english",
|
| 8 |
use_auth_token=True
|
| 9 |
)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def add_note(title, content):
|
| 14 |
if not content.strip():
|
| 15 |
-
return "
|
| 16 |
result = classifier(content)[0]
|
| 17 |
label = result["label"]
|
| 18 |
-
|
| 19 |
"title": title or "Sin título",
|
| 20 |
"content": content,
|
| 21 |
"category": label
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
for
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
with gr.Blocks(theme=gr.themes.Base(primary_hue="blue")) as demo:
|
| 34 |
gr.Markdown("<h1 style='color:#0099ff; text-align:center;'>BATUTO_IA_NOTAS</h1>")
|
| 35 |
gr.Markdown("<p style='color:#e3eaff; text-align:center;'>Bloc de notas inteligente con tema oscuro y fuentes azules.</p>")
|
|
|
|
| 36 |
with gr.Row():
|
| 37 |
title = gr.Textbox(label="Título", elem_id="titlebox")
|
| 38 |
content = gr.Textbox(lines=4, label="Contenido de la nota", elem_id="contentbox")
|
| 39 |
submit = gr.Button("Guardar nota", elem_id="savebtn")
|
| 40 |
-
show_notes = gr.HTML()
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
)
|
| 50 |
|
| 51 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
classifier = pipeline(
|
| 5 |
"text-classification",
|
| 6 |
model="distilbert-base-uncased-finetuned-sst-2-english",
|
| 7 |
use_auth_token=True
|
| 8 |
)
|
| 9 |
|
| 10 |
+
def add_note(title, content, state):
|
|
|
|
|
|
|
| 11 |
if not content.strip():
|
| 12 |
+
return gr.update(), state, "⚠️ Escribe contenido (no vacío)."
|
| 13 |
result = classifier(content)[0]
|
| 14 |
label = result["label"]
|
| 15 |
+
note = {
|
| 16 |
"title": title or "Sin título",
|
| 17 |
"content": content,
|
| 18 |
"category": label
|
| 19 |
+
}
|
| 20 |
+
notes = state or []
|
| 21 |
+
notes.append(note)
|
| 22 |
+
notes_html = ""
|
| 23 |
+
for idx, n in enumerate(notes):
|
| 24 |
+
notes_html += f'''
|
| 25 |
+
<div style="border:1px solid #1a1a2e;background:#222;border-radius:8px;padding:10px;margin-bottom:18px;position:relative;">
|
| 26 |
+
<h3 style="color:#0099ff;">{n["title"]}</h3>
|
| 27 |
+
<p style="color:#e3eaff;">{n["content"]}</p>
|
| 28 |
+
<strong style="color:#0099ff;">Categoría IA: {n["category"]}</strong>
|
| 29 |
+
<button onclick="navigator.clipboard.writeText(`{n["title"]}\\n{n["content"]}`)" style="position:absolute;top:10px;right:10px;background:#23233a;color:#62cfff;border:none;padding:5px 7px;border-radius:6px;cursor:pointer;">Copiar</button>
|
| 30 |
+
</div>
|
| 31 |
+
'''
|
| 32 |
+
notes_html += """
|
| 33 |
+
<button onclick="downloadNotes()" style="background:#0099ff;color:white;border:none;padding:10px 18px;border-radius:8px;cursor:pointer;">
|
| 34 |
+
Descargar todas tus notas
|
| 35 |
+
</button>
|
| 36 |
+
<script>
|
| 37 |
+
function downloadNotes() {
|
| 38 |
+
let divs = document.querySelectorAll('div[style*="border:1px solid"]');
|
| 39 |
+
let text = "";
|
| 40 |
+
divs.forEach((div) => {
|
| 41 |
+
text += div.querySelector('h3').textContent + "\\n";
|
| 42 |
+
text += div.querySelector('p').textContent + "\\n\\n";
|
| 43 |
+
});
|
| 44 |
+
let blob = new Blob([text], {type:"text/plain"});
|
| 45 |
+
let link = document.createElement('a');
|
| 46 |
+
link.href = window.URL.createObjectURL(blob);
|
| 47 |
+
link.download = "mis_notas.txt";
|
| 48 |
+
link.click();
|
| 49 |
+
}
|
| 50 |
+
</script>
|
| 51 |
+
"""
|
| 52 |
+
return notes_html, notes, "✅ Nota guardada"
|
| 53 |
|
| 54 |
with gr.Blocks(theme=gr.themes.Base(primary_hue="blue")) as demo:
|
| 55 |
gr.Markdown("<h1 style='color:#0099ff; text-align:center;'>BATUTO_IA_NOTAS</h1>")
|
| 56 |
gr.Markdown("<p style='color:#e3eaff; text-align:center;'>Bloc de notas inteligente con tema oscuro y fuentes azules.</p>")
|
| 57 |
+
state = gr.State([])
|
| 58 |
with gr.Row():
|
| 59 |
title = gr.Textbox(label="Título", elem_id="titlebox")
|
| 60 |
content = gr.Textbox(lines=4, label="Contenido de la nota", elem_id="contentbox")
|
| 61 |
submit = gr.Button("Guardar nota", elem_id="savebtn")
|
| 62 |
+
show_notes = gr.HTML(label="Tus notas")
|
| 63 |
+
status = gr.Markdown()
|
| 64 |
+
submit.click(add_note, [title, content, state], [show_notes, state, status])
|
| 65 |
+
gr.Markdown("""
|
| 66 |
+
<style>
|
| 67 |
+
body { background: #181824; }
|
| 68 |
+
#titlebox, #contentbox, #savebtn { color: #0099ff !important; background: #23233a; border-radius: 8px; }
|
| 69 |
+
</style>
|
| 70 |
+
""")
|
|
|
|
| 71 |
|
| 72 |
demo.launch()
|