Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
import requests
|
|
|
4 |
|
5 |
-
# Загрузка переменных окружения
|
6 |
BASE_URL = os.getenv("BASE_URL")
|
7 |
API_KEY = os.getenv("API_KEY")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
"prompt": prompt,
|
14 |
-
"
|
15 |
-
"sampling_steps":
|
16 |
-
"cfg_scale":
|
17 |
-
"seed":
|
18 |
}
|
19 |
|
20 |
-
|
21 |
-
headers = {
|
22 |
-
"Authorization": f"Bearer {API_KEY}"
|
23 |
-
}
|
24 |
-
|
25 |
-
# Отправка запроса к модели
|
26 |
-
response = requests.post(BASE_URL, json=data, headers=headers)
|
27 |
-
|
28 |
-
# Получение сгенерированного изображения
|
29 |
-
generated_image = response.content
|
30 |
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
-
# Определение интерфейса Gradio
|
34 |
iface = gr.Interface(
|
35 |
fn=generate_image,
|
36 |
inputs=[
|
37 |
-
gr.Textbox("
|
38 |
-
gr.Textbox("
|
39 |
-
gr.Slider(1, 30, 1, label="Sampling Steps"),
|
40 |
-
gr.Slider(1, 20, 1, label="CFG Scale"),
|
41 |
-
gr.
|
42 |
],
|
43 |
-
outputs=gr.Image(),
|
44 |
live=True,
|
45 |
-
|
46 |
-
theme="compact",
|
47 |
-
interpretation="default",
|
48 |
-
allow_flagging=False,
|
49 |
-
allow_screenshot=False,
|
50 |
-
allow_download=False,
|
51 |
-
allow_duplicate=False,
|
52 |
-
show_input=True,
|
53 |
-
show_output=True,
|
54 |
-
show_interpretation=True,
|
55 |
-
show_flag=False,
|
56 |
-
show_screenshot=False,
|
57 |
-
show_download=False
|
58 |
)
|
59 |
|
60 |
-
# Запуск веб-приложения
|
61 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import requests
|
3 |
+
import os
|
4 |
|
|
|
5 |
BASE_URL = os.getenv("BASE_URL")
|
6 |
API_KEY = os.getenv("API_KEY")
|
7 |
|
8 |
+
def generate_image(prompt, negative_prompt, sampling_steps, cfg_scale, seed):
|
9 |
+
url = f"{BASE_URL}/generate"
|
10 |
+
headers = {"Authorization": f"Bearer {API_KEY}"}
|
11 |
+
params = {
|
12 |
"prompt": prompt,
|
13 |
+
"negative_prompt": negative_prompt,
|
14 |
+
"sampling_steps": sampling_steps,
|
15 |
+
"cfg_scale": cfg_scale,
|
16 |
+
"seed": seed
|
17 |
}
|
18 |
|
19 |
+
response = requests.get(url, headers=headers, params=params)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
if response.status_code == 200:
|
22 |
+
return response.content
|
23 |
+
else:
|
24 |
+
return None
|
25 |
|
|
|
26 |
iface = gr.Interface(
|
27 |
fn=generate_image,
|
28 |
inputs=[
|
29 |
+
gr.Textbox("prompt", label="Prompt"),
|
30 |
+
gr.Textbox("negative_prompt", label="Negative Prompt"),
|
31 |
+
gr.Slider(1, 30, 1, label="Sampling Steps", default=10),
|
32 |
+
gr.Slider(1, 20, 1, label="CFG Scale", default=10),
|
33 |
+
gr.Textbox("seed", label="Seed (Default: -1)"),
|
34 |
],
|
35 |
+
outputs=gr.Image(label="Generated Image"),
|
36 |
live=True,
|
37 |
+
theme="compact"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
)
|
39 |
|
|
|
40 |
iface.launch()
|