app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from io import BytesIO
|
| 3 |
from random import randint
|
| 4 |
from all_models import models
|
| 5 |
|
|
@@ -30,37 +29,25 @@ def gen_fn(model_str, prompt):
|
|
| 30 |
if model_str == 'NA':
|
| 31 |
return None
|
| 32 |
noise = str(randint(0, 99999999))
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
if isinstance(result, str):
|
| 36 |
-
response = requests.get(result)
|
| 37 |
-
img = Image.open(BytesIO(response.content))
|
| 38 |
-
elif isinstance(result, bytes):
|
| 39 |
-
img = Image.open(BytesIO(result))
|
| 40 |
-
else:
|
| 41 |
-
return None
|
| 42 |
-
|
| 43 |
-
buffered = BytesIO()
|
| 44 |
-
img.save(buffered, format="PNG")
|
| 45 |
-
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 46 |
-
return f"data:image/png;base64,{img_str}"
|
| 47 |
|
| 48 |
def make_me():
|
| 49 |
with gr.Row():
|
| 50 |
-
with gr.Column(scale=
|
| 51 |
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image", show_label=True, interactive=False, show_share_button=False) for m in default_models]
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from random import randint
|
| 3 |
from all_models import models
|
| 4 |
|
|
|
|
| 29 |
if model_str == 'NA':
|
| 30 |
return None
|
| 31 |
noise = str(randint(0, 99999999))
|
| 32 |
+
return models_load[model_str](f'{prompt} {noise}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
def make_me():
|
| 35 |
with gr.Row():
|
| 36 |
+
with gr.Column(scale=4):
|
| 37 |
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
| 38 |
+
|
| 39 |
+
with gr.Column(scale=1):
|
| 40 |
+
gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
|
| 41 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
| 42 |
+
|
| 43 |
+
def on_generate_click():
|
| 44 |
+
return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
|
| 45 |
+
|
| 46 |
+
def on_stop_click():
|
| 47 |
+
return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
| 48 |
+
|
| 49 |
+
gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
|
| 50 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
| 51 |
|
| 52 |
with gr.Row():
|
| 53 |
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image", show_label=True, interactive=False, show_share_button=False) for m in default_models]
|