Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
|
|
|
|
4 |
|
5 |
# Функция для генерации изображения с помощью DALL-E 3 API
|
6 |
def generate_image(prompt, seed, sampling_method, cfg, width, height):
|
@@ -19,33 +21,11 @@ def generate_image(prompt, seed, sampling_method, cfg, width, height):
|
|
19 |
}
|
20 |
response = requests.post("https://api.openai.com/v1/engines/dalle-3/images", headers=headers, json=data)
|
21 |
if response.status_code == 200:
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
else:
|
25 |
-
return
|
26 |
|
27 |
-
#
|
28 |
-
css = """
|
29 |
-
footer { display: none; }
|
30 |
-
"""
|
31 |
-
|
32 |
-
with gr.Blocks(css=css) as demo:
|
33 |
-
with gr.Tabs():
|
34 |
-
with gr.TabItem("Базовые настройки"):
|
35 |
-
prompt_input = gr.Textbox(label="Введите текст для генерации изображения", lines=3, placeholder="Введите текст...")
|
36 |
-
with gr.TabItem("Расширенные настройки"):
|
37 |
-
seed_input = gr.Number(label="Сид", value=0)
|
38 |
-
sampling_method_input = gr.Dropdown(label="Метод семплирования", choices=["Default", "DDIM", "PLMS"], value="Default")
|
39 |
-
cfg_input = gr.Slider(label="CFG", minimum=1, maximum=20, value=7)
|
40 |
-
width_input = gr.Number(label="Ширина", value=512)
|
41 |
-
height_input = gr.Number(label="Высота", value=512)
|
42 |
-
generate_button = gr.Button("Генерация", variant="primary")
|
43 |
-
output_image = gr.Image()
|
44 |
-
|
45 |
-
generate_button.click(
|
46 |
-
generate_image,
|
47 |
-
inputs=[prompt_input, seed_input, sampling_method_input, cfg_input, width_input, height_input],
|
48 |
-
outputs=output_image,
|
49 |
-
)
|
50 |
-
|
51 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
|
7 |
# Функция для генерации изображения с помощью DALL-E 3 API
|
8 |
def generate_image(prompt, seed, sampling_method, cfg, width, height):
|
|
|
21 |
}
|
22 |
response = requests.post("https://api.openai.com/v1/engines/dalle-3/images", headers=headers, json=data)
|
23 |
if response.status_code == 200:
|
24 |
+
image_data = response.json()["data"][0]["url"]
|
25 |
+
image_response = requests.get(image_data)
|
26 |
+
image = Image.open(io.BytesIO(image_response.content))
|
27 |
+
return image
|
28 |
else:
|
29 |
+
return None # Возвращаем None в случае ошибки
|
30 |
|
31 |
+
# Остальная часть кода без изменений...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|