phenomenon1981 commited on
Commit
a586d92
1 Parent(s): d889880

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -76
app.py CHANGED
@@ -1,106 +1,98 @@
1
  import gradio as gr
2
  import os
3
  import sys
4
- import random
5
  from pathlib import Path
6
- from concurrent.futures import ThreadPoolExecutor
7
 
8
- #Load the models and the text generation model
9
  text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
 
 
10
  proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
11
  proc2=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
12
  proc3=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
13
  proc4=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
 
14
  proc5=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
15
  proc6=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
16
  proc7=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
17
  proc8=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
18
 
19
- #Create a function to handle the errors
20
- def handle_errors(func):
21
- def wrapper(*args, **kwargs):
22
- try:
23
- return func(*args, **kwargs)
24
- except Exception as e:
25
- return "An error occurred: " + str(e)
26
- return wrapper
27
-
28
-
29
- # Define the functions for each model
30
- @handle_errors
31
- def send_it1(inputs):
32
- return proc1(inputs)
33
-
34
- @handle_errors
35
- def send_it2(inputs):
36
- return proc2(inputs)
37
-
38
- @handle_errors
39
- def send_it3(inputs):
40
- return proc3(inputs)
41
-
42
- @handle_errors
43
- def send_it4(inputs):
44
- return proc4(inputs)
45
-
46
- @handle_errors
47
- def send_it5(inputs):
48
- return proc5(inputs)
49
-
50
- @handle_errors
51
- def send_it6(inputs):
52
- return proc6(inputs)
53
 
54
- @handle_errors
55
- def send_it7(inputs):
56
- return proc7(inputs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- @handle_errors
59
- def send_it8(inputs):
60
- return proc8(inputs)
61
 
62
-
63
- # Create a function to generate the prompts
64
- @handle_errors
65
  def get_prompts(prompt_text):
66
  return text_gen(prompt_text)
67
 
 
 
68
  with gr.Blocks() as myface:
69
  with gr.Row():
70
- input_text = gr.Textbox(label="Short Prompt")
71
- see_prompts = gr.Button("Magic Prompt")
72
-
 
73
  with gr.Row():
74
- prompt = gr.Textbox(label="Prettified Prompt")
75
- run = gr.Button("Launch")
76
-
 
 
77
  with gr.Row():
78
- output1 = gr.Image(label="DreamlikeArt PhotoReal 1")
79
- output2 = gr.Image(label="DreamlikeArt PhotoReal 2")
80
- output3 = gr.Image(label="DreamlikeArt PhotoReal 3")
81
- output4 = gr.Image(label="DreamlikeArt PhotoReal 4")
82
-
83
  with gr.Row():
84
- output5 = gr.Image(label="DreamlikeArt Diffusion 1")
85
- output6 = gr.Image(label="DreamlikeArt Diffusion 2")
86
- output7 = gr.Image(label="DreamlikeArt Diffusion 3")
87
- output8 = gr.Image(label="DreamlikeArt Diffusion 4")
88
 
89
- # Handle button clicks
90
- see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
91
 
92
- # Use a thread pool to run the models in parallel
93
- executor = ThreadPoolExecutor()
94
- run.click(lambda : [executor.submit(send_it1, prompt),
95
- executor.submit(send_it2, prompt),
96
- executor.submit(send_it3, prompt),
97
- executor.submit(send_it4, prompt),
98
- executor.submit(send_it5, prompt),
99
- executor.submit(send_it6, prompt),
100
- executor.submit(send_it7, prompt),
101
- executor.submit(send_it8, prompt)
102
- ],
103
- inputs=[prompt],
104
- outputs=[output1, output2, output3, output4, output5, output6, output7, output8])
105
 
 
 
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import os
3
  import sys
 
4
  from pathlib import Path
 
5
 
6
+
7
  text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
8
+
9
+
10
  proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
11
  proc2=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
12
  proc3=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
13
  proc4=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
14
+
15
  proc5=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
16
  proc6=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
17
  proc7=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
18
  proc8=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ def send_it1(inputs,proc1=proc1):
22
+ output1=proc1(inputs)
23
+ return(output1)
24
+ def send_it2(inputs,proc2=proc2):
25
+ output2=proc2(inputs)
26
+ return(output2)
27
+ def send_it3(inputs,proc3=proc3):
28
+ output3=proc3(inputs)
29
+ return(output3)
30
+ def send_it4(inputs,proc4=proc4):
31
+ output4=proc4(inputs)
32
+ return(output4)
33
+
34
+ def send_it5(inputs,proc5=proc5):
35
+ output5=proc5(inputs)
36
+ return(output5)
37
+ def send_it6(inputs,proc6=proc6):
38
+ output6=proc6(inputs)
39
+ return(output6)
40
+ def send_it7(inputs,proc7=proc7):
41
+ output7=proc7(inputs)
42
+ return(output7)
43
+ def send_it8(inputs,proc8=proc8):
44
+ output8=proc8(inputs)
45
+ return(output8)
46
 
 
 
 
47
 
 
 
 
48
  def get_prompts(prompt_text):
49
  return text_gen(prompt_text)
50
 
51
+
52
+
53
  with gr.Blocks() as myface:
54
  with gr.Row():
55
+
56
+
57
+ input_text=gr.Textbox(label="Short Prompt")
58
+ see_prompts=gr.Button("Magic Prompt")
59
  with gr.Row():
60
+
61
+ prompt=gr.Textbox(label="Prettified Prompt")
62
+ run=gr.Button("Launch")
63
+
64
+
65
  with gr.Row():
66
+ output1=gr.Image(label="DreamlikeArt PhotoReal 1")
67
+ output2=gr.Image(label="DreamlikeArt PhotoReal 2")
68
+ output3=gr.Image(label="DreamlikeArt PhotoReal 3")
69
+ output4=gr.Image(label="DreamlikeArt PhotoReal 4")
 
70
  with gr.Row():
71
+ output5=gr.Image(label="DreamlikeArt Diffusion 1")
72
+ output6=gr.Image(label="DreamlikeArt Diffusion 2")
73
+ output7=gr.Image(label="DreamlikeArt Diffusion 3")
74
+ output8=gr.Image(label="DreamlikeArt Diffusion 4")
75
 
 
 
76
 
77
+ #def set_models(model_name1, model_name2, model_name3, model_name4):
78
+
79
+ #return(proc1,proc2,proc3,proc4)
 
 
 
 
 
 
 
 
 
 
80
 
81
+ #run.click(set_models, inputs=[model_name1, model_name2, model_name3, model_name4], outputs=[proc1,proc2,proc3,proc4])
82
+ #run.click(send_it, inputs=[prompt], outputs=[output1, output2, output3, output4])
83
 
84
+
85
+ see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
86
+
87
+ run.click(send_it1, inputs=[prompt], outputs=[output1])
88
+ run.click(send_it2, inputs=[prompt], outputs=[output2])
89
+ run.click(send_it3, inputs=[prompt], outputs=[output3])
90
+ run.click(send_it4, inputs=[prompt], outputs=[output4])
91
+ run.click(send_it5, inputs=[prompt], outputs=[output5])
92
+ run.click(send_it6, inputs=[prompt], outputs=[output6])
93
+ run.click(send_it7, inputs=[prompt], outputs=[output7])
94
+ run.click(send_it8, inputs=[prompt], outputs=[output8])
95
+
96
+
97
+ myface.queue(concurrency_count=8)
98
+ myface.launch(enable_queue=True, inline=True)