Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import json
|
| 2 |
import time
|
| 3 |
-
|
| 4 |
import requests
|
| 5 |
import base64
|
| 6 |
from io import BytesIO
|
|
@@ -40,10 +39,10 @@ class Text2ImageAPI:
|
|
| 40 |
data = response.json()
|
| 41 |
return data[0]['id']
|
| 42 |
|
| 43 |
-
def generate(self, prompt, negative, style, width, height, model):
|
| 44 |
params = {
|
| 45 |
"type": "GENERATE",
|
| 46 |
-
"numImages":
|
| 47 |
"style": f"{style}",
|
| 48 |
"width": width,
|
| 49 |
"height": height,
|
|
@@ -73,16 +72,14 @@ class Text2ImageAPI:
|
|
| 73 |
time.sleep(delay)
|
| 74 |
|
| 75 |
|
| 76 |
-
def api_gradio(prompt, negative, style, width, height):
|
| 77 |
api = Text2ImageAPI('https://api-key.fusionbrain.ai/', api_key, secret_key)
|
| 78 |
model_id = api.get_model()
|
| 79 |
-
uuid = api.generate(prompt, negative, styles[style], width, height, model_id)
|
| 80 |
images = api.check_generation(uuid)
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
return image
|
| 86 |
|
| 87 |
|
| 88 |
|
|
@@ -97,14 +94,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 97 |
with gr.Accordion("Дополнительные настройки", open=False):
|
| 98 |
with gr.Row():
|
| 99 |
negative = gr.Textbox(label="Отрицательная подсказка", placeholder="Исключения, чего не должно быть на фото", max_lines=3, lines=1, interactive=True, scale=20)
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
with gr.Row():
|
| 106 |
-
gallery = gr.
|
| 107 |
|
| 108 |
-
button.click(api_gradio, inputs=[prompt, negative, style, width, height], outputs=gallery)
|
| 109 |
|
| 110 |
-
demo.queue(max_size=100).launch(show_api=False)
|
|
|
|
| 1 |
import json
|
| 2 |
import time
|
|
|
|
| 3 |
import requests
|
| 4 |
import base64
|
| 5 |
from io import BytesIO
|
|
|
|
| 39 |
data = response.json()
|
| 40 |
return data[0]['id']
|
| 41 |
|
| 42 |
+
def generate(self, prompt, negative, style, width, height, model, num_images):
|
| 43 |
params = {
|
| 44 |
"type": "GENERATE",
|
| 45 |
+
"numImages": num_images,
|
| 46 |
"style": f"{style}",
|
| 47 |
"width": width,
|
| 48 |
"height": height,
|
|
|
|
| 72 |
time.sleep(delay)
|
| 73 |
|
| 74 |
|
| 75 |
+
def api_gradio(prompt, negative, style, width, height, num_images):
|
| 76 |
api = Text2ImageAPI('https://api-key.fusionbrain.ai/', api_key, secret_key)
|
| 77 |
model_id = api.get_model()
|
| 78 |
+
uuid = api.generate(prompt, negative, styles[style], width, height, model_id, num_images)
|
| 79 |
images = api.check_generation(uuid)
|
| 80 |
|
| 81 |
+
decoded_images = [Image.open(BytesIO(base64.b64decode(image))) for image in images]
|
| 82 |
+
return decoded_images
|
|
|
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
|
|
|
|
| 94 |
with gr.Accordion("Дополнительные настройки", open=False):
|
| 95 |
with gr.Row():
|
| 96 |
negative = gr.Textbox(label="Отрицательная подсказка", placeholder="Исключения, чего не должно быть на фото", max_lines=3, lines=1, interactive=True, scale=20)
|
| 97 |
+
with gr.Row():
|
| 98 |
+
width = gr.Slider(label="Ширина", minimum=128, maximum=1024, step=1, value=1024, interactive=True)
|
| 99 |
+
height = gr.Slider(label="Высота", minimum=128, maximum=1024, step=1, value=1024, interactive=True)
|
| 100 |
+
with gr.Row():
|
| 101 |
+
num_images = gr.Slider(label="Количество изображений", minimum=1, maximum=4, step=1, value=1, interactive=True)
|
| 102 |
with gr.Row():
|
| 103 |
+
gallery = gr.Gallery(show_label=False).style(grid=[2], height="auto")
|
| 104 |
|
| 105 |
+
button.click(api_gradio, inputs=[prompt, negative, style, width, height, num_images], outputs=gallery)
|
| 106 |
|
| 107 |
+
demo.queue(max_size=100).launch(show_api=False)
|