Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
notes = []
|
| 12 |
+
|
| 13 |
+
def add_note(title, content):
|
| 14 |
+
if not content.strip():
|
| 15 |
+
return "Por favor ingresa contenido para la nota."
|
| 16 |
+
result = classifier(content)[0]
|
| 17 |
+
label = result["label"]
|
| 18 |
+
notes.append({
|
| 19 |
+
"title": title or "Sin t铆tulo",
|
| 20 |
+
"content": content,
|
| 21 |
+
"category": label
|
| 22 |
+
})
|
| 23 |
+
|
| 24 |
+
# Construir HTML para mostrar todas las notas
|
| 25 |
+
display = ""
|
| 26 |
+
for note in notes:
|
| 27 |
+
display += f"<div style='border:1px solid #1a1a2e; background:#222; border-radius:8px; padding:10px; margin-bottom:12px;'>"
|
| 28 |
+
display += f"<h3 style='color:#0099ff;'>{note['title']}</h3>"
|
| 29 |
+
display += f"<p style='color:#e3eaff;'>{note['content']}</p>"
|
| 30 |
+
display += f"<strong style='color:#0099ff;'>Categor铆a sugerida: {note['category']}</strong></div>"
|
| 31 |
+
return display
|
| 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 |
+
submit.click(add_note, [title, content], show_notes)
|
| 42 |
+
gr.Markdown(
|
| 43 |
+
"""
|
| 44 |
+
<style>
|
| 45 |
+
body { background: #181824; }
|
| 46 |
+
#titlebox, #contentbox, #savebtn { color: #0099ff !important; background: #23233a; border-radius: 8px; }
|
| 47 |
+
</style>
|
| 48 |
+
"""
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
demo.launch()
|