Felguk commited on
Commit
3c69552
·
verified ·
1 Parent(s): 66c6476

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -36,6 +36,21 @@ def convert_to_text(url):
36
  except requests.exceptions.RequestException as e:
37
  return f"Ошибка: {e}", "", None # Возвращаем сообщение об ошибке, пустую строку и None для файла
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  # Подключаем CSS-файл
40
  css = "app.css"
41
 
@@ -49,17 +64,14 @@ with gr.Blocks(css=css) as demo:
49
 
50
  with gr.Row():
51
  results_output = gr.Textbox(label="Результаты запроса", interactive=False)
52
- text_output = gr.Textbox(label="Текстовое содержимое", interactive=True)
53
 
54
  with gr.Row():
55
- download_button = gr.Button("Скачать в .txt", elem_classes="download-button")
56
  file_output = gr.File(label="Скачать файл", visible=False) # Скрытый компонент для скачивания файла
57
 
58
  submit_button = gr.Button("Загрузить")
59
  submit_button.click(fn=convert_to_text, inputs=url_input, outputs=[results_output, text_output, file_output])
60
-
61
- # Показываем кнопку "Скачать в .txt" только если есть файл для скачивания
62
- download_button.click(fn=lambda: file_output.update(visible=True), outputs=file_output)
63
 
64
  # Запускаем интерфейс
65
  demo.launch()
 
36
  except requests.exceptions.RequestException as e:
37
  return f"Ошибка: {e}", "", None # Возвращаем сообщение об ошибке, пустую строку и None для файла
38
 
39
+ # HTML и JavaScript для кнопки "Скопировать код"
40
+ copy_button_html = """
41
+ <script>
42
+ function copyCode() {
43
+ const text = document.querySelector("#output-text textarea").value;
44
+ navigator.clipboard.writeText(text).then(() => {
45
+ alert("Текст скопирован в буфер обмена!");
46
+ }).catch(() => {
47
+ alert("Не удалось скопировать текст.");
48
+ });
49
+ }
50
+ </script>
51
+ <button onclick="copyCode()">Скопировать код</button>
52
+ """
53
+
54
  # Подключаем CSS-файл
55
  css = "app.css"
56
 
 
64
 
65
  with gr.Row():
66
  results_output = gr.Textbox(label="Результаты запроса", interactive=False)
67
+ text_output = gr.Textbox(label="Текстовое содержимое", interactive=True, elem_id="output-text")
68
 
69
  with gr.Row():
70
+ gr.HTML(copy_button_html) # Добавляем кнопку "Скопировать код"
71
  file_output = gr.File(label="Скачать файл", visible=False) # Скрытый компонент для скачивания файла
72
 
73
  submit_button = gr.Button("Загрузить")
74
  submit_button.click(fn=convert_to_text, inputs=url_input, outputs=[results_output, text_output, file_output])
 
 
 
75
 
76
  # Запускаем интерфейс
77
  demo.launch()