Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,6 @@ import gradio as gr
|
|
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,16 +20,31 @@ def generate_minecraft_command(minecraft_version, description=""):
|
|
30 |
|
31 |
if 'choices' in data and len(data['choices']) > 0:
|
32 |
command = data['choices'][0]['message']['content'].strip()
|
33 |
-
|
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 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
iface.launch()
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def generate_minecraft_command(minecraft_version, description=""):
|
7 |
headers = {
|
|
|
20 |
|
21 |
if 'choices' in data and len(data['choices']) > 0:
|
22 |
command = data['choices'][0]['message']['content'].strip()
|
23 |
+
return command
|
|
|
24 |
elif 'error' in data:
|
25 |
error_message = data['error']['message']
|
26 |
return f'Ошибка: {error_message}'
|
27 |
else:
|
28 |
return f'Не удалось сгенерировать команду. {data}'
|
29 |
|
30 |
+
def is_description_empty(description):
|
31 |
+
return description.strip() == ""
|
32 |
+
|
33 |
+
iface = gr.Interface(
|
34 |
+
fn=generate_minecraft_command,
|
35 |
+
inputs=[
|
36 |
+
gr.Textbox(label="Версия Minecraft", placeholder="Minecraft Java 1.20"),
|
37 |
+
gr.Textbox(label="Описание команды", default="", type="text")
|
38 |
+
],
|
39 |
+
outputs="text",
|
40 |
+
title="Minecraft Command Generator",
|
41 |
+
live=True,
|
42 |
+
interpretation="default",
|
43 |
+
examples=[
|
44 |
+
["Minecraft Java 1.20", "Телепортироваться к игроку"],
|
45 |
+
["Minecraft Java 1.20", "Выдать алмазный меч"]
|
46 |
+
],
|
47 |
+
layout="vertical",
|
48 |
+
disabled=is_description_empty
|
49 |
+
)
|
50 |
iface.launch()
|