Rooni commited on
Commit
7e6300e
·
1 Parent(s): e59f3f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
app.py CHANGED
@@ -2,11 +2,16 @@ import gradio as gr
2
  import requests
3
  import json
4
  import os
5
- import pyperclip # Импорт библиотеки для копирования в буфер обмена
 
6
 
7
- def copy_to_clipboard(output_data):
8
- pyperclip.copy(output_data)
9
- return "Скопировано в буфер обмена"
 
 
 
 
10
 
11
  def generate_minecraft_command(minecraft_version, description=""):
12
  headers = {
@@ -25,30 +30,16 @@ def generate_minecraft_command(minecraft_version, description=""):
25
 
26
  if 'choices' in data and len(data['choices']) > 0:
27
  command = data['choices'][0]['message']['content'].strip()
28
- return command
 
29
  elif 'error' in data:
30
  error_message = data['error']['message']
31
  return f'Ошибка: {error_message}'
32
  else:
33
  return f'Не удалось сгенерировать команду. {data}'
34
 
35
- iface = gr.Interface(
36
- fn=generate_minecraft_command,
37
- inputs=[
38
- gr.Textbox(label="Версия Minecraft", placeholder="Minecraft Java 1.20"),
39
- gr.Textbox(label="Описание команды")
40
- ],
41
- outputs=gr.Textbox(label="Сгенерированная команда"),
42
- title="Minecraft Command Generator"
43
- )
44
-
45
- copy_button = gr.Button(
46
- text="Копировать в буфер обмена",
47
- icon="📋",
48
- type="primary",
49
- on_click=copy_to_clipboard,
50
- inputs=[iface.outputs]
51
- )
52
-
53
- iface.add_output(copy_button)
54
  iface.launch()
 
2
  import requests
3
  import json
4
  import os
5
+ from tkinter import Tk
6
+ from tkinter import simpledialog
7
 
8
+ def copy_to_clipboard(text):
9
+ root = Tk()
10
+ root.withdraw()
11
+ root.clipboard_clear()
12
+ root.clipboard_append(text)
13
+ root.update()
14
+ root.destroy()
15
 
16
  def generate_minecraft_command(minecraft_version, description=""):
17
  headers = {
 
30
 
31
  if 'choices' in data and len(data['choices']) > 0:
32
  command = data['choices'][0]['message']['content'].strip()
33
+ copy_button = f'<img src="https://img.icons8.com/ios/15/000000/copy.png" style="cursor:pointer;" onclick="copyToClipboard(\'{command}\')" title="Копировать в буфер обмена">'
34
+ return f'{command} {copy_button}'
35
  elif 'error' in data:
36
  error_message = data['error']['message']
37
  return f'Ошибка: {error_message}'
38
  else:
39
  return f'Не удалось сгенерировать команду. {data}'
40
 
41
+ iface = gr.Interface(fn=generate_minecraft_command, inputs=[
42
+ gr.Textbox(label="Версия Minecraft", placeholder="Minecraft Java 1.20"),
43
+ gr.Textbox(label="Описание команды")
44
+ ], outputs=gr.Textbox(), title="Minecraft Command Generator")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  iface.launch()