Spaces:
Running
Running
import gradio as gr | |
import requests | |
import json | |
import os | |
def generate_minecraft_command(description): | |
headers = { | |
'Content-Type': 'application/json', | |
'Authorization': f'Bearer {os.getenv("API_KEY")}' | |
} | |
payload = { | |
'prompt': f'Напиши пожалуйста команду для Minecraft JAVA 1.20, под описание: "{description}"', | |
'max_tokens': 50 | |
} | |
response = requests.post(os.getenv("BASE_URL"), headers=headers, json=payload) | |
data = json.loads(response.text) | |
if 'choices' in data and len(data['choices']) > 0: | |
command = data['choices'][0]['text'].strip() | |
return command | |
elif 'error' in data: | |
error_message = data['error'] | |
return f'Ошибка: {error_message}' | |
else: | |
return 'Не удалось сгенерировать команду для Minecraft.' | |
iface = gr.Interface(fn=generate_minecraft_command, inputs="text", outputs="text", title="Minecraft Command Generator") | |
iface.launch() | |