Jonny001 commited on
Commit
77efc8c
·
verified ·
1 Parent(s): bf36fb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -49
app.py CHANGED
@@ -1,50 +1,62 @@
1
  import gradio as gr
2
- import random
3
-
4
- # Load each model separately
5
- model1 = gr.load("models/pimpilikipilapi1/NSFW_master")
6
- model2 = gr.load("models/prashanth970/flux-lora-uncensored")
7
- model3 = gr.load("models/DiegoJR1973/NSFW-TrioHMH-Flux")
8
-
9
- def generate_images(text, seed, width, height, guidance_scale, num_inference_steps):
10
- if seed is not None:
11
- random.seed(seed)
12
-
13
- # Generate images using each model with the text prompt only
14
- result_image1 = model1(text)
15
- result_image2 = model2(text)
16
- result_image3 = model3(text)
17
-
18
- # Print parameters for debugging
19
- print(f"Text: {text}, Seed: {seed}, Width: {width}, Height: {height}, Guidance Scale: {guidance_scale}, Steps: {num_inference_steps}")
20
-
21
- return result_image1, result_image2, result_image3
22
-
23
- def randomize_parameters():
24
- seed = random.randint(0, 999999)
25
- width = random.randint(512, 2048)
26
- height = random.randint(512, 2048)
27
- guidance_scale = round(random.uniform(0.1, 20.0), 1)
28
- num_inference_steps = random.randint(1, 40)
29
-
30
- return seed, width, height, guidance_scale, num_inference_steps
31
-
32
- interface = gr.Interface(
33
- fn=generate_images,
34
- inputs=[
35
- gr.Textbox(label="Type here your imagination:", placeholder="Type or click an example..."),
36
- gr.Slider(label="Seed", minimum=0, maximum=999999, step=1),
37
- gr.Slider(label="Width", minimum=512, maximum=2048, step=64, value=1024),
38
- gr.Slider(label="Height", minimum=512, maximum=2048, step=64, value=1024),
39
- gr.Slider(label="Guidance Scale", minimum=0.1, maximum=20.0, step=0.1, value=3.0),
40
- gr.Slider(label="Number of inference steps", minimum=1, maximum=40, step=1, value=28),
41
- ],
42
- outputs=[
43
- gr.Image(label="Generated Image from NSFW_master"),
44
- gr.Image(label="Generated Image from flux-lora-uncensored"),
45
- gr.Image(label="Generated Image from NSFW-TrioHMH-Flux")
46
- ],
47
- description="Generate images with three different models based on your prompt. Note: the models run on the CPU, which may affect performance.",
48
- )
49
-
50
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import time
3
+
4
+
5
+ model1 = gr.Interface.load("models/pimpilikipilapi1/NSFW_master", live=False, preprocess=True, postprocess=False)
6
+ model2 = gr.Interface.load("models/prashanth970/flux-lora-uncensored", live=False, preprocess=True, postprocess=False)
7
+ model3 = gr.Interface.load("models/DiegoJR1973/NSFW-TrioHMH-Flux", live=False, preprocess=True, postprocess=False)
8
+
9
+ models = {
10
+ 1: model1,
11
+ 2: model2,
12
+ 3: model3
13
+ }
14
+
15
+ def send_it_idx(idx):
16
+ def send_it_fn(prompt):
17
+ model = models.get(idx)
18
+ if model:
19
+ return model(prompt)
20
+ return None
21
+ return send_it_fn
22
+
23
+ def clear_fn():
24
+ return None, None, None
25
+
26
+ with gr.Blocks(title="SD Models") as my_interface:
27
+ with gr.Column(scale=12):
28
+ with gr.Row():
29
+ primary_prompt = gr.Textbox(label="Prompt", value="")
30
+ with gr.Row(scale=6):
31
+ run = gr.Button("Run", variant="primary")
32
+ clear_btn = gr.Button("Clear")
33
+
34
+ sd_outputs = {}
35
+ for idx, model in models.items():
36
+ with gr.Column(scale=3, min_width=200):
37
+ with gr.Box():
38
+ sd_outputs[idx] = gr.Image(label=f"Model {idx}")
39
+
40
+ with gr.Row(visible=False):
41
+ start_box = gr.Number(interactive=False)
42
+ end_box = gr.Number(interactive=False)
43
+ tog_box = gr.Textbox(value=0, interactive=False)
44
+
45
+ def all_task_start():
46
+ t_stamp = time.time()
47
+ return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
48
+
49
+ primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
50
+ run.click(all_task_start, None, [start_box, end_box, tog_box])
51
+
52
+ for idx, model in models.items():
53
+ run.click(model, inputs=[primary_prompt], outputs=[sd_outputs[idx]])
54
+
55
+ clear_btn.click(
56
+ clear_fn,
57
+ None,
58
+ [primary_prompt, *list(sd_outputs.values())]
59
+ )
60
+
61
+ my_interface.queue(concurrency_count=100, status_update_rate=1)
62
+ my_interface.launch(inline=True, show_api=False)