Rooni commited on
Commit
fdc9379
·
1 Parent(s): bd7cb09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -26,7 +26,7 @@ def dzen(theme, description=""):
26
 
27
  if 'choices' in data and len(data['choices']) > 0:
28
  command = data['choices'][0]['message']['content'].strip()
29
- return f'{command} <span onclick="copyToClipboard(\'{command}\')" style="cursor: pointer;">📋</span>'
30
  elif 'error' in data:
31
  error_message = data['error']['message']
32
  gr.alert(f'Ошибка: {error_message}')
@@ -38,8 +38,31 @@ def dzen(theme, description=""):
38
  gr.alert(f'Ошибка при получении данных от сервера. Статус код: {response.status_code}')
39
  return ''
40
 
 
 
 
 
 
 
 
41
  iface = gr.Interface(fn=dzen, inputs=[
42
  gr.Textbox(label="Тема", placeholder=""),
43
  gr.Textbox(label="Дополнительный текст")
44
- ], outputs=gr.Textbox(label="Пост"), title="Генератор постов Яндекс Дзен")
45
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  if 'choices' in data and len(data['choices']) > 0:
28
  command = data['choices'][0]['message']['content'].strip()
29
+ return command
30
  elif 'error' in data:
31
  error_message = data['error']['message']
32
  gr.alert(f'Ошибка: {error_message}')
 
38
  gr.alert(f'Ошибка при получении данных от сервера. Статус код: {response.status_code}')
39
  return ''
40
 
41
+ def output_fn(output):
42
+ if output:
43
+ # Если ответ не пустой, добавляем иконку копирования
44
+ return f'{output} <button onclick="copyToClipboard(\'{output}\')">📋 Copy</button>'
45
+ else:
46
+ return ''
47
+
48
  iface = gr.Interface(fn=dzen, inputs=[
49
  gr.Textbox(label="Тема", placeholder=""),
50
  gr.Textbox(label="Дополнительный текст")
51
+ ], outputs=gr.HTML(label="Пост"), title="Генератор постов Яндекс Дзен", live=True)
52
+
53
+ # Вспомогательный скрипт для копирования текста в буфер обмена
54
+ copy_script = """
55
+ <script>
56
+ function copyToClipboard(text) {
57
+ var textArea = document.createElement("textarea");
58
+ textArea.value = text;
59
+ document.body.appendChild(textArea);
60
+ textArea.select();
61
+ document.execCommand('copy');
62
+ document.body.removeChild(textArea);
63
+ alert('Текст скопирован в буфер обмена!');
64
+ }
65
+ </script>
66
+ """
67
+
68
+ iface.launch(share=True, debug=True, custom_css=copy_script)