Aist1 commited on
Commit
3c3b1c5
·
verified ·
1 Parent(s): 59fc22e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -38,6 +38,7 @@ with gr.Blocks(css=CSS, title="Тишина внутри") as demo:
38
  gr.Markdown("## 🌿 Тишина внутри")
39
  gr.Markdown(f"### «{get_daily_prompt()}»")
40
 
 
41
  main_note = gr.Textbox(
42
  label="Твоя заметка",
43
  placeholder="Напиши всё, что приходит…",
@@ -58,8 +59,9 @@ with gr.Blocks(css=CSS, title="Тишина внутри") as demo:
58
  </button>
59
  """)
60
 
 
61
  gr.Markdown("### Практики")
62
- for i,name in enumerate(PRACTICES):
63
  with gr.Accordion(name, open=False):
64
  practice_box = gr.Textbox(
65
  label="Твои впечатления",
@@ -67,6 +69,7 @@ with gr.Blocks(css=CSS, title="Тишина внутри") as demo:
67
  lines=3,
68
  elem_id=f"practice_{i}"
69
  )
 
70
  gr.HTML(f"""
71
  <button style="background:#a8a29e;color:white;border:none;padding:8px 16px;border-radius:6px;margin:8px 0;cursor:pointer;"
72
  onclick="
@@ -80,7 +83,8 @@ with gr.Blocks(css=CSS, title="Тишина внутри") as demo:
80
  </button>
81
  """)
82
 
83
- gr.HTML("""
 
84
  <button style="background:#a8a29e;color:white;border:none;padding:8px 16px;border-radius:6px;margin:8px 0;cursor:pointer;"
85
  onclick="
86
  let txt = '— Главная заметка —\\n' + (localStorage.getItem('main-note') || 'пусто') + '\\n\\n';
@@ -93,51 +97,51 @@ with gr.Blocks(css=CSS, title="Тишина внутри") as demo:
93
  ">
94
  👀 Показать все заметки
95
  </button>
96
- """)
97
 
98
  <button style="background:#a8a29e;color:white;border:none;padding:8px 16px;border-radius:6px;margin:8px 0;cursor:pointer;"
99
  onclick="
100
- (async () => {{
101
- if (!window.jspdf) {{
102
  const s = document.createElement('script');
103
  s.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js';
104
  document.head.appendChild(s);
105
  await new Promise(r => s.onload = r);
106
- }}
107
  const {{ jsPDF }} = window.jspdf;
108
  const doc = new jsPDF();
109
  doc.setFontSize(16);
110
  doc.text('Тишина внутри — мои заметки', 14, 20);
111
  let y = 30;
112
  const main = localStorage.getItem('main-note');
113
- if (main) {{
114
  doc.setFontSize(12);
115
  doc.text('Главная заметка:', 14, y);
116
  y += 6;
117
  const lines = doc.splitTextToSize(main, 180);
118
  doc.text(lines, 14, y);
119
  y += lines.length * 6 + 10;
120
- }}
121
  const names = ['Письмо от Тени', 'Кто наблюдает?', 'Голос из зеркала', 'Письмо от будущего себя', 'Тело знает'];
122
- for (let i = 0; i < 5; i++) {{
123
  const val = localStorage.getItem('practice-' + i);
124
- if (val) {{
125
  doc.setFontSize(12);
126
  doc.text(names[i] + ':', 14, y);
127
  y += 6;
128
  const lines = doc.splitTextToSize(val, 180);
129
- if (y + lines.length * 6 > 280) {{ doc.addPage(); y = 20; }}
130
  doc.text(lines, 14, y);
131
  y += lines.length * 6 + 10;
132
- }}
133
- }}
134
  doc.save('тишина-внутри-' + new Date().toISOString().slice(0,10) + '.pdf');
135
- }})();
136
  ">
137
  📥 Экспортировать в PDF
138
  </button>
139
  """)
140
 
 
141
  gr.HTML("""
142
  <script>
143
  setTimeout(() => {
 
38
  gr.Markdown("## 🌿 Тишина внутри")
39
  gr.Markdown(f"### «{get_daily_prompt()}»")
40
 
41
+ # Основная заметка
42
  main_note = gr.Textbox(
43
  label="Твоя заметка",
44
  placeholder="Напиши всё, что приходит…",
 
59
  </button>
60
  """)
61
 
62
+ # Практики
63
  gr.Markdown("### Практики")
64
+ for i, name in enumerate(PRACTICES):
65
  with gr.Accordion(name, open=False):
66
  practice_box = gr.Textbox(
67
  label="Твои впечатления",
 
69
  lines=3,
70
  elem_id=f"practice_{i}"
71
  )
72
+ # ВАЖНО: используем f-строку, чтобы {i} подставилось на стороне Python
73
  gr.HTML(f"""
74
  <button style="background:#a8a29e;color:white;border:none;padding:8px 16px;border-radius:6px;margin:8px 0;cursor:pointer;"
75
  onclick="
 
83
  </button>
84
  """)
85
 
86
+ # Кнопки действий
87
+ gr.HTML("""
88
  <button style="background:#a8a29e;color:white;border:none;padding:8px 16px;border-radius:6px;margin:8px 0;cursor:pointer;"
89
  onclick="
90
  let txt = '— Главная заметка —\\n' + (localStorage.getItem('main-note') || 'пусто') + '\\n\\n';
 
97
  ">
98
  👀 Показать все заметки
99
  </button>
 
100
 
101
  <button style="background:#a8a29e;color:white;border:none;padding:8px 16px;border-radius:6px;margin:8px 0;cursor:pointer;"
102
  onclick="
103
+ (async () => {
104
+ if (!window.jspdf) {
105
  const s = document.createElement('script');
106
  s.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js';
107
  document.head.appendChild(s);
108
  await new Promise(r => s.onload = r);
109
+ }
110
  const {{ jsPDF }} = window.jspdf;
111
  const doc = new jsPDF();
112
  doc.setFontSize(16);
113
  doc.text('Тишина внутри — мои заметки', 14, 20);
114
  let y = 30;
115
  const main = localStorage.getItem('main-note');
116
+ if (main) {
117
  doc.setFontSize(12);
118
  doc.text('Главная заметка:', 14, y);
119
  y += 6;
120
  const lines = doc.splitTextToSize(main, 180);
121
  doc.text(lines, 14, y);
122
  y += lines.length * 6 + 10;
123
+ }
124
  const names = ['Письмо от Тени', 'Кто наблюдает?', 'Голос из зеркала', 'Письмо от будущего себя', 'Тело знает'];
125
+ for (let i = 0; i < 5; i++) {
126
  const val = localStorage.getItem('practice-' + i);
127
+ if (val) {
128
  doc.setFontSize(12);
129
  doc.text(names[i] + ':', 14, y);
130
  y += 6;
131
  const lines = doc.splitTextToSize(val, 180);
132
+ if (y + lines.length * 6 > 280) { doc.addPage(); y = 20; }
133
  doc.text(lines, 14, y);
134
  y += lines.length * 6 + 10;
135
+ }
136
+ }
137
  doc.save('тишина-внутри-' + new Date().toISOString().slice(0,10) + '.pdf');
138
+ })();
139
  ">
140
  📥 Экспортировать в PDF
141
  </button>
142
  """)
143
 
144
+ # Загрузка сохранённых данных при старте
145
  gr.HTML("""
146
  <script>
147
  setTimeout(() => {