BATUTO-ART commited on
Commit
1779505
·
verified ·
1 Parent(s): 565cdee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -26
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
- 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()
 
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()