File size: 1,361 Bytes
e92393d
 
 
 
 
785fd2e
65c5950
c0e5dbf
 
 
00ccf46
785fd2e
 
 
 
c0e5dbf
 
 
e92393d
785fd2e
 
00ccf46
785fd2e
c0e5dbf
785fd2e
 
c0e5dbf
785fd2e
 
c0e5dbf
 
785fd2e
ccb8280
c0e5dbf
 
00ccf46
e92393d
00ccf46
757f1cf
00ccf46
785fd2e
757f1cf
00ccf46
 
e92393d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
import requests
import json
import os

def generate_minecraft_command(description, image):
    try:
        headers = {
            'Authorization': f'Bearer {os.getenv("API_KEY")}'
        }

        files = {'image': ('image.png', image.read(), 'image/png')}

        data = {
            'messages': [{'role': 'system', 'content': description}],
            'max_tokens': 10000,
            'model': os.getenv("MODEL")
        }

        response = requests.post(os.getenv("BASE_URL"), headers=headers, data=data, files=files)
        response.raise_for_status()

        data = json.loads(response.text)

        if 'choices' in data and len(data['choices']) > 0:
            command = data['choices'][0]['message']['content'].strip()
            return command
        elif 'error' in data:
            error_message = data['error']['message']
            return f'Ошибка: {error_message}'
        else:
            return f'Не удалось сгенерировать команду. {data}'

    except Exception as e:
        return f'Произошла ошибка: {str(e)}'

iface = gr.Interface(
    fn=generate_minecraft_command,
    inputs=[
        gr.Textbox(label="Запрос"),
        gr.Image(label="Изображение")
    ],
    outputs=gr.Textbox(label="Ответ"),
    title="GPT"
)
iface.launch()