Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from random import randint
|
| 3 |
from all_models import models
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
def load_fn(models):
|
| 8 |
global models_load
|
| 9 |
models_load = {}
|
|
@@ -16,40 +15,37 @@ def load_fn(models):
|
|
| 16 |
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
| 17 |
models_load.update({model: m})
|
| 18 |
|
| 19 |
-
|
| 20 |
load_fn(models)
|
| 21 |
|
| 22 |
-
|
| 23 |
num_models = 100
|
| 24 |
default_models = models[:num_models]
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
def extend_choices(choices):
|
| 29 |
return choices + (num_models - len(choices)) * ['NA']
|
| 30 |
|
| 31 |
-
|
| 32 |
def update_imgbox(choices):
|
| 33 |
choices_plus = extend_choices(choices)
|
| 34 |
-
return [gr.Image(None, label
|
| 35 |
|
| 36 |
-
|
| 37 |
def gen_fn(model_str, prompt):
|
| 38 |
if model_str == 'NA':
|
| 39 |
return None
|
| 40 |
-
noise = str(
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
-
with gr.Tab('The Dream'):
|
| 47 |
-
txt_input = gr.Textbox(label
|
| 48 |
-
gen_button = gr.Button('Generate
|
| 49 |
-
stop_button = gr.Button('Stop', variant
|
| 50 |
-
gen_button.click(lambda s: gr.update(interactive
|
| 51 |
gr.HTML(
|
| 52 |
-
|
| 53 |
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
| 54 |
<div>
|
| 55 |
<body>
|
|
@@ -59,26 +55,32 @@ with gr.Blocks() as demo:
|
|
| 59 |
</div>
|
| 60 |
</div>
|
| 61 |
"""
|
| 62 |
-
|
| 63 |
with gr.Row():
|
| 64 |
-
|
| 65 |
-
current_models = [gr.Textbox(m, visible
|
| 66 |
-
|
| 67 |
-
|
|
|
|
| 68 |
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
| 69 |
-
stop_button.click(lambda s: gr.update(interactive
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
with gr.Accordion('Model selection'):
|
| 71 |
-
model_choice = gr.CheckboxGroup(models, label
|
| 72 |
-
model_choice.change(update_imgbox, model_choice,
|
| 73 |
model_choice.change(extend_choices, model_choice, current_models)
|
|
|
|
| 74 |
with gr.Row():
|
| 75 |
gr.HTML(
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
-
demo.queue(concurrency_count
|
| 84 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import moviepy.editor as mp
|
| 3 |
from random import randint
|
| 4 |
from all_models import models
|
| 5 |
|
|
|
|
|
|
|
| 6 |
def load_fn(models):
|
| 7 |
global models_load
|
| 8 |
models_load = {}
|
|
|
|
| 15 |
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
| 16 |
models_load.update({model: m})
|
| 17 |
|
|
|
|
| 18 |
load_fn(models)
|
| 19 |
|
|
|
|
| 20 |
num_models = 100
|
| 21 |
default_models = models[:num_models]
|
| 22 |
|
|
|
|
|
|
|
| 23 |
def extend_choices(choices):
|
| 24 |
return choices + (num_models - len(choices)) * ['NA']
|
| 25 |
|
|
|
|
| 26 |
def update_imgbox(choices):
|
| 27 |
choices_plus = extend_choices(choices)
|
| 28 |
+
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
| 29 |
|
|
|
|
| 30 |
def gen_fn(model_str, prompt):
|
| 31 |
if model_str == 'NA':
|
| 32 |
return None
|
| 33 |
+
noise = str(randint(0, 99999999999))
|
| 34 |
+
img = models_load[model_str](f'{prompt} {noise}')
|
| 35 |
+
return img
|
| 36 |
|
| 37 |
+
def create_video(images, fps=24):
|
| 38 |
+
clip = mp.ImageSequenceClip(images, fps=fps)
|
| 39 |
+
return clip
|
| 40 |
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
+
with gr.Tab('The Dream'):
|
| 43 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=4).style(container=False, min_width=1200)
|
| 44 |
+
gen_button = gr.Button('Generate images and create video')
|
| 45 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False)
|
| 46 |
+
gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
|
| 47 |
gr.HTML(
|
| 48 |
+
"""
|
| 49 |
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
| 50 |
<div>
|
| 51 |
<body>
|
|
|
|
| 55 |
</div>
|
| 56 |
</div>
|
| 57 |
"""
|
| 58 |
+
)
|
| 59 |
with gr.Row():
|
| 60 |
+
output_images = [gr.Image(label=m, min_width=480) for m in default_models]
|
| 61 |
+
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
| 62 |
+
output_video = gr.Video(label='Generated Video')
|
| 63 |
+
|
| 64 |
+
for m, o in zip(current_models, output_images):
|
| 65 |
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
| 66 |
+
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
| 67 |
+
|
| 68 |
+
gen_video_event = gen_button.click(lambda s: create_video([o.data for o in output_images if o.data is not None]), None, output_video)
|
| 69 |
+
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_video_event])
|
| 70 |
+
|
| 71 |
with gr.Accordion('Model selection'):
|
| 72 |
+
model_choice = gr.CheckboxGroup(models, label=f'Choose up to {num_models} different models from the 755 available!', value=default_models, multiselect=True, max_choices=num_models, interactive=True, filterable=False)
|
| 73 |
+
model_choice.change(update_imgbox, model_choice, output_images)
|
| 74 |
model_choice.change(extend_choices, model_choice, current_models)
|
| 75 |
+
|
| 76 |
with gr.Row():
|
| 77 |
gr.HTML(
|
| 78 |
+
"""
|
| 79 |
+
<div class="footer">
|
| 80 |
+
<p> Based on the <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn, the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier!
|
| 81 |
+
</p>
|
| 82 |
+
"""
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
demo.queue(concurrency_count=200)
|
| 86 |
+
demo.launch()
|