Update app.py
Browse files
app.py
CHANGED
|
@@ -1,108 +1,74 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from random import randint
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
"John6666/3x3x3mixxl-v2-sdxl-spo",
|
| 15 |
-
"John6666/3x3x3mixxl-v2-sdxl",
|
| 16 |
-
],
|
| 17 |
-
"Group C": [
|
| 18 |
-
"John6666/3x3x3mixxl-v2-sdxl-spo",
|
| 19 |
-
"John6666/3x3x3mixxl-v2-sdxl",
|
| 20 |
-
"John6666/titania-mix-realistic-pony-gbv10-sdxl",
|
| 21 |
-
],
|
| 22 |
-
"Group D": [
|
| 23 |
-
"John6666/titania-mix-realistic-pony-gbv20-sdxl",
|
| 24 |
-
"John6666/titania-mix-realistic-pony-gbv30-sdxl",
|
| 25 |
-
"John6666/mala-anime-mix-nsfw-pony-xl-v3-sdxl",
|
| 26 |
-
],
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
# Placeholder for models
|
| 30 |
-
models_load = {model: None for group in model_groups.values() for model in group}
|
| 31 |
-
|
| 32 |
-
# Function to simulate model loading
|
| 33 |
def load_fn(models):
|
| 34 |
-
|
| 35 |
for model in models:
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
models_load = load_fn(models_load.keys())
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if model_str == 'NA':
|
| 48 |
-
return None
|
| 49 |
|
| 50 |
noise = str(randint(0, 9999))
|
| 51 |
combined_prompt = f'{prompt} {model_str} {noise}'
|
| 52 |
-
print(f"Generating with prompt: {combined_prompt}")
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
try:
|
| 55 |
-
result = models_load[model_str](combined_prompt)
|
| 56 |
-
tallies[model_str] += 1
|
| 57 |
-
return result, tallies
|
| 58 |
-
except Exception as e:
|
| 59 |
-
print(f"Error generating for {model_str}: {e}")
|
| 60 |
-
return None, tallies
|
| 61 |
|
| 62 |
-
# Build the Gradio interface
|
| 63 |
def make_me():
|
| 64 |
with gr.Row():
|
| 65 |
-
|
| 66 |
-
choices=list(model_groups.keys()),
|
| 67 |
-
label="Select Model Group",
|
| 68 |
-
value="Group A", # Default group
|
| 69 |
-
)
|
| 70 |
-
txt_input = gr.Textbox(label='Your prompt:', lines=2, value="mohawk femboy racecar driver")
|
| 71 |
gen_button = gr.Button('Generate images', elem_id="generate-btn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
with gr.Row():
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
selected_models = model_groups[group_name]
|
| 80 |
-
# Create image and tally elements for the selected group
|
| 81 |
-
outputs = [gr.Image(label=model, visible=True, width=170, height=170) for model in selected_models]
|
| 82 |
-
tallies_dict = {model: 0 for model in selected_models}
|
| 83 |
-
tally_boxes = [gr.Textbox(value="0", label=f"Tally for {model}", interactive=False) for model in selected_models]
|
| 84 |
-
return outputs, tally_boxes, tallies_dict
|
| 85 |
-
|
| 86 |
-
model_group_selector.change(
|
| 87 |
-
update_outputs,
|
| 88 |
-
inputs=[model_group_selector],
|
| 89 |
-
outputs=[output, tallies],
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
def generate_images(prompt, outputs, tallies):
|
| 93 |
-
for idx, model_output in enumerate(outputs):
|
| 94 |
-
model_str = list(tallies.keys())[idx]
|
| 95 |
-
result, tallies = gen_fn(model_str, prompt, tallies)
|
| 96 |
-
model_output.update(value=result)
|
| 97 |
-
for idx, tally_box in enumerate(tallies.values()):
|
| 98 |
-
tally_box.update(value=str(tally_box))
|
| 99 |
-
return tallies
|
| 100 |
-
|
| 101 |
-
gen_button.click(
|
| 102 |
-
generate_images,
|
| 103 |
-
inputs=[txt_input, output, tallies],
|
| 104 |
-
outputs=[tallies],
|
| 105 |
-
)
|
| 106 |
|
| 107 |
js_code = """
|
| 108 |
<script>
|
|
@@ -119,6 +85,7 @@ js_code = """
|
|
| 119 |
"""
|
| 120 |
|
| 121 |
with gr.Blocks() as demo:
|
|
|
|
| 122 |
make_me()
|
| 123 |
gr.Markdown(js_code)
|
| 124 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from random import randint
|
| 3 |
+
from all_models import models
|
| 4 |
from datetime import datetime
|
| 5 |
|
| 6 |
+
kii = "mohawk femboy racecar driver"
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_current_time():
|
| 10 |
+
now = datetime.now()
|
| 11 |
+
current_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
| 12 |
+
return f'{kii} {current_time}'
|
| 13 |
+
|
| 14 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def load_fn(models):
|
| 16 |
+
models_load = {}
|
| 17 |
for model in models:
|
| 18 |
+
if model not in models_load:
|
| 19 |
+
try:
|
| 20 |
+
m = gr.load(f'models/{model}') # Adjust `gr.load` as needed
|
| 21 |
+
except Exception as error:
|
| 22 |
+
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
| 23 |
+
models_load[model] = m
|
| 24 |
+
return models_load
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
models_load = load_fn(models)
|
| 28 |
+
|
| 29 |
+
num_models = len(models)
|
| 30 |
+
default_models = models[:num_models]
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
+
def extend_choices(choices):
|
| 34 |
+
return choices + (num_models - len(choices)) * ['NA']
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def update_imgbox(choices):
|
| 38 |
+
choices_plus = extend_choices(choices)
|
| 39 |
+
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def gen_fn(model_str, prompt):
|
| 43 |
if model_str == 'NA':
|
| 44 |
+
return None
|
| 45 |
|
| 46 |
noise = str(randint(0, 9999))
|
| 47 |
combined_prompt = f'{prompt} {model_str} {noise}'
|
| 48 |
+
print(f"Generating with prompt: {combined_prompt}") # Debug line
|
| 49 |
+
|
| 50 |
+
return models_load.get(model_str, lambda txt: None)(f'{prompt} {noise}')
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
| 53 |
def make_me():
|
| 54 |
with gr.Row():
|
| 55 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=2, value=kii)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
gen_button = gr.Button('Generate images', elem_id="generate-btn")
|
| 57 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False)
|
| 58 |
+
gen_button.click(lambda: gr.update(interactive=True), None, stop_button)
|
| 59 |
+
|
| 60 |
+
gr.HTML("""
|
| 61 |
+
<div style="text-align: center; max-width: 100%; margin: 0 auto;">
|
| 62 |
+
<body></body>
|
| 63 |
+
</div>
|
| 64 |
+
""")
|
| 65 |
|
| 66 |
with gr.Row():
|
| 67 |
+
output = [gr.Image(label=m, width=170, height=170) for m in default_models]
|
| 68 |
+
current_models = [gr.Textbox(value=m, visible=False) for m in default_models]
|
| 69 |
+
for m, o in zip(current_models, output):
|
| 70 |
+
gen_button.click(gen_fn, inputs=[m, txt_input], outputs=o)
|
| 71 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
js_code = """
|
| 74 |
<script>
|
|
|
|
| 85 |
"""
|
| 86 |
|
| 87 |
with gr.Blocks() as demo:
|
| 88 |
+
gr.Markdown("<div></div>")
|
| 89 |
make_me()
|
| 90 |
gr.Markdown(js_code)
|
| 91 |
|