Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,9 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import json
|
4 |
import os
|
|
|
|
|
|
|
5 |
|
6 |
def generate_minecraft_command(description, image):
|
7 |
try:
|
@@ -9,7 +12,12 @@ def generate_minecraft_command(description, image):
|
|
9 |
'Authorization': f'Bearer {os.getenv("API_KEY")}'
|
10 |
}
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
data = {
|
15 |
'messages': [{'role': 'system', 'content': description}],
|
@@ -38,7 +46,7 @@ iface = gr.Interface(
|
|
38 |
fn=generate_minecraft_command,
|
39 |
inputs=[
|
40 |
gr.Textbox(label="Запрос"),
|
41 |
-
gr.Image(label="Изображение")
|
42 |
],
|
43 |
outputs=gr.Textbox(label="Ответ"),
|
44 |
title="GPT"
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
import os
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image
|
7 |
+
from io import BytesIO
|
8 |
|
9 |
def generate_minecraft_command(description, image):
|
10 |
try:
|
|
|
12 |
'Authorization': f'Bearer {os.getenv("API_KEY")}'
|
13 |
}
|
14 |
|
15 |
+
# Преобразуем изображение в формат bytes
|
16 |
+
image_bytes = BytesIO()
|
17 |
+
image.save(image_bytes, format='PNG')
|
18 |
+
image_data = image_bytes.getvalue()
|
19 |
+
|
20 |
+
files = {'image': ('image.png', image_data, 'image/png')}
|
21 |
|
22 |
data = {
|
23 |
'messages': [{'role': 'system', 'content': description}],
|
|
|
46 |
fn=generate_minecraft_command,
|
47 |
inputs=[
|
48 |
gr.Textbox(label="Запрос"),
|
49 |
+
gr.Image(label="Изображение", type="pil") # Указываем Gradio использовать PIL для обработки изображения
|
50 |
],
|
51 |
outputs=gr.Textbox(label="Ответ"),
|
52 |
title="GPT"
|