Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,9 @@ import string
|
|
6 |
import time
|
7 |
from queue import Queue
|
8 |
from threading import Thread
|
9 |
-
import requests
|
10 |
-
|
11 |
-
model_interface = gr.Interface.load("models/segmind/SSD-1B")
|
12 |
-
API_URL = "https://api-inference.huggingface.co/models/segmind/SSD-1B"
|
13 |
|
|
|
|
|
14 |
|
15 |
def restart_script_periodically():
|
16 |
while True:
|
@@ -46,69 +44,119 @@ import uuid # Import the UUID library
|
|
46 |
# Existing code...
|
47 |
|
48 |
request_counter = 0 # Global counter to track requests
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
"
|
54 |
-
"
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
with gr.Column(elem_id="col-container"):
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
with gr.Row(variant="compact"):
|
113 |
prompt = gr.Textbox(
|
114 |
lines=8,
|
@@ -120,19 +168,7 @@ with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{displa
|
|
120 |
container=False,
|
121 |
textarea={'height': '400px'}
|
122 |
)
|
123 |
-
|
124 |
run = gr.Button("Generate Images").style(full_width=False)
|
125 |
-
|
126 |
-
with gr.Accordion("Advanced options", open=False):
|
127 |
-
with gr.Row():
|
128 |
-
style_selection = gr.Radio(
|
129 |
-
show_label=True, container=True, interactive=True,
|
130 |
-
choices=IMAGE_STYLES,
|
131 |
-
value=DEFAULT_IMAGE_STYLE,
|
132 |
-
label='Image Style'
|
133 |
-
)
|
134 |
-
|
135 |
-
negative_prompt = gr.Textbox(label="Negative Prompt (Optional)", placeholder="Example: blurry, unfocused", lines=2)
|
136 |
|
137 |
with gr.Row():
|
138 |
with gr.Row():
|
@@ -140,11 +176,13 @@ with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{displa
|
|
140 |
|
141 |
with gr.Row():
|
142 |
with gr.Row():
|
143 |
-
output1 = gr.Image(label="", show_label=False, show_share_button=False)
|
144 |
-
output2 = gr.Image(label="", show_label=False, show_share_button=False)
|
145 |
|
146 |
-
|
147 |
-
run.click(
|
148 |
-
run.click(
|
|
|
|
|
149 |
|
150 |
demo.launch(enable_queue=True, inline=True)
|
|
|
6 |
import time
|
7 |
from queue import Queue
|
8 |
from threading import Thread
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
text_gen = gr.Interface.load("models/Gustavosta/MagicPrompt-Stable-Diffusion")
|
11 |
+
proc1 = gr.Interface.load("models/openskyml/midjourney-v4-xl")
|
12 |
|
13 |
def restart_script_periodically():
|
14 |
while True:
|
|
|
44 |
# Existing code...
|
45 |
|
46 |
request_counter = 0 # Global counter to track requests
|
47 |
+
|
48 |
+
def send_it1(inputs, noise_level, proc=proc1):
|
49 |
+
global request_counter
|
50 |
+
request_counter += 1
|
51 |
+
timestamp = f"{time.time()}_{request_counter}"
|
52 |
+
prompt_with_noise = add_random_noise(inputs, noise_level) + f" - {timestamp}"
|
53 |
+
try:
|
54 |
+
while queue.qsize() >= queue_threshold:
|
55 |
+
time.sleep(2)
|
56 |
+
queue.put(prompt_with_noise)
|
57 |
+
output = proc(prompt_with_noise)
|
58 |
+
return output
|
59 |
+
except Exception as e:
|
60 |
+
# Display a generic error message to the user
|
61 |
+
raise gr.Error("Experiencing high demand. Please retry shortly. Thank you for your patience.")
|
62 |
+
|
63 |
+
import random
|
64 |
+
|
65 |
+
import random
|
66 |
+
import time
|
67 |
+
|
68 |
+
# ... (existing code)
|
69 |
+
|
70 |
+
import random
|
71 |
+
import time
|
72 |
+
|
73 |
+
# ... (existing code)
|
74 |
+
|
75 |
+
def get_prompts(prompt_text):
|
76 |
+
if not prompt_text:
|
77 |
+
return "Please enter text before generating prompts.رجاء ادخل النص اولا"
|
78 |
+
raise gr.Error("Please enter text before generating prompts.رجاء ادخل النص اولا")
|
79 |
+
else:
|
80 |
+
global request_counter
|
81 |
+
request_counter += 1
|
82 |
+
timestamp = f"{time.time()}_{request_counter}"
|
83 |
+
|
84 |
+
options = [
|
85 |
+
"Cyberpunk android",
|
86 |
+
"2060",
|
87 |
+
"newyork",
|
88 |
+
", style of laurie greasley" , "studio ghibli" , "akira toriyama" , "james gilleard" , "genshin impact" , "trending pixiv fanbox" , "acrylic palette knife, 4k, vibrant colors, devinart, trending on artstation, low details"
|
89 |
+
", Editorial Photography, Shot on 70mm lens, Depth of Field, Bokeh, DOF, Tilt Blur, Shutter Speed 1/1000, F/22, 32k, Super-Resolution, award winning,",
|
90 |
+
", high detail, warm lighting, godrays, vivid, beautiful, trending on artstation, by jordan grimmer, huge scene, grass, art greg rutkowski ",
|
91 |
+
", highly detailed, digital painting, artstation, illustration, art by artgerm and greg rutkowski and alphonse mucha.",
|
92 |
+
", Charlie Bowater, stanley artgerm lau, a character portrait, sots art, sharp focus, smooth, aesthetic, extremely detailed, octane render,solo, dark industrial background, rtx, rock clothes, cinematic light, intricate detail, highly detailed, high res, detailed facial features",
|
93 |
+
", portrait photograph" , "realistic" , "concept art" , "elegant, highly detailed" , "intricate, sharp focus, depth of field, f/1. 8, 85mm, medium shot, mid shot, (((professionally color graded)))" ," sharp focus, bright soft diffused light" , "(volumetric fog),",
|
94 |
+
",Cinematic film still" ," (dark city street:1.2)" , "(cold colors), damp, moist, intricate details" ,"shallow depth of field, [volumetric fog]" , "cinematic lighting, reflections, photographed on a Canon EOS R5, 50mm lens, F/2.8, HDR, 8k resolution" , "cinematic film still from cyberpunk movie" , "volumetric fog, (RAW, analog, masterpiece, best quality, soft particles, 8k, flawless perfect face, intricate details" , "trending on artstation, trending on cgsociety, dlsr, ultra sharp, hdr, rtx, antialiasing, canon 5d foto))" , "((skin details, high detailed skin texture))" , "(((perfect face))), (perfect eyes)))",
|
95 |
+
"facinating and imposing" , "fantasy digital art, octane render, beautiful composition" ," trending on artstation, award-winning photograph, masterpiece",
|
96 |
+
|
97 |
+
"portrait elf", "intricate, elegant", "highly detailed" , "digital painting" , "artstation", "concept art, smooth, sharp focus" , "illustration, art by artgerm and greg rutkowski and alphonse mucha, 8k",
|
98 |
+
|
99 |
+
" intricate, elegant, highly detailed" , "digital painting, artstation, concept art, smooth, sharp focus" ," illustration, art by artgerm and greg rutkowski and alphonse mucha, 8k",
|
100 |
+
" matte painting, highly detailed, dynamic lighting, cinematic, realism, realistic" , "photo real, sunset,detailed, high contrast, denoised, centered, michael whelan",
|
101 |
+
|
102 |
+
|
103 |
+
"cyborg| full-length portrait", "detailed face", "symmetric| steampunk", "cyberpunk| cyborg| intricate detailed| to scale", "hyperrealistic", "cinematic lighting| digital art| concept art",
|
104 |
+
|
105 |
+
"photo of a ultra realistic" ," dramatic light, pale sunrise, cinematic lighting" , "battered, low angle, trending on artstation, 4k, hyper realistic" , "focused, extreme details" , "unreal engine 5, cinematic, masterpiece, art by studio ghibli, intricate artwork by john william turner",
|
106 |
+
"street| old town| old city| winter| heavy snow", "| comprehensive cinematic", "| Atmosphere| Masterpiece",
|
107 |
+
"fantasy, intricate, elegant, highly detailed" , "digital painting, artstation, concept art, matte, sharp focus, illustration, hearthstone, art by artgerm and greg rutkowski and alphonse mucha, hdr 4k, 8k",
|
108 |
+
|
109 |
+
" (((wild west))) environment, Utah landscape, ultra realistic" , "concept art, elegant, ((intricate)), ((highly detailed)), depth of field, ((professionally color graded)), soft ambient lighting, dusk, 8k, art by artgerm and greg rutkowski and alphonse mucha",
|
110 |
+
|
111 |
+
"Incredibly detailed technical diagram, split into complex geometric shapes and flowers growing from the shapes" ," Chiaroscuro lighting, fine intricate details –q 2 –upbeta –v 4 –v 4",
|
112 |
+
" : concept art::1 cyberpunk::1 splatter paint::1 wide angle lens::2 Zdzislaw Beksinski style" , "winter storm, ultra detailed| 4k –v 4",
|
113 |
+
"photo of a ultra realistic, dramatic light, pale sunrise" , "cinematic lighting, battered" , "low angle, trending on artstation" , "4k, hyper realistic, focused, extreme details, unreal engine 5, cinematic, masterpiece" , "art by studio ghibli, intricate artwork by john william turner",
|
114 |
+
|
115 |
+
|
116 |
+
"mdjrny-v4 style, incredible highly detailed space ship" , "space background, perfect composition" , "beautiful detailed, intricate, insanely detailed, octane render" , "trending on artstation, artistic, photorealistic, concept art, soft natural volumetric cinematic perfect light, chiaroscuro" , "award winning photograph, masterpiece, oil on canvas, raphael, caravaggio, greg rutkowski, beeple, beksinski, giger style",
|
117 |
+
|
118 |
+
"japanese style shrine on top of a misty mountain overgrown" , "hyper realistic, lush gnarly plants, 8 k, denoised, by greg rutkowski" , "tom bagshaw, james gurney cinematic lighting",
|
119 |
+
|
120 |
+
"insanely detailed and intricate digital illustration by Hayao Miyazaki, Ismail Inceoglu, M.W. Kaluta and Yoshitaka Amano"," a masterpiece, close-up, 8k resolution, trending on artstation, delicate, watercolor, soft,",
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
"neon light sign in design of face", "| precise lineart", "| intricate | realistic | studio quality | cinematic | luminescence", "| character design | concept art", "| highly detailed", "| illustration", "| digital art | digital painting",
|
125 |
+
|
126 |
+
|
127 |
+
# Add other prompt options here...
|
128 |
+
|
129 |
+
]
|
130 |
+
|
131 |
+
if prompt_text:
|
132 |
+
chosen_option = random.choice(options)
|
133 |
+
return text_gen(f"{prompt_text}, {chosen_option} - {timestamp}")
|
134 |
+
else:
|
135 |
+
return text_gen("", timestamp)
|
136 |
+
|
137 |
+
|
138 |
+
|
139 |
+
# Existing code...
|
140 |
+
|
141 |
+
# Existing code...
|
142 |
+
|
143 |
+
with gr.Blocks(css=".gradio-container {background-color: #F5F5F5;} .dark .gradio-container {background-color: #330066;} footer{display:none !important;}",) as demo:
|
144 |
+
|
145 |
|
146 |
with gr.Column(elem_id="col-container"):
|
147 |
+
with gr.Row(variant="compact"):
|
148 |
+
input_text = gr.Textbox(
|
149 |
+
lines=8,
|
150 |
+
label="Short Prompt",
|
151 |
+
show_label=False,
|
152 |
+
max_lines=10,
|
153 |
+
placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!",
|
154 |
+
).style(
|
155 |
+
container=False,
|
156 |
+
textarea={'height': '400px'}
|
157 |
+
)
|
158 |
+
see_prompts = gr.Button("✨ Magic Prompt ✨").style(full_width=False)
|
159 |
+
|
160 |
with gr.Row(variant="compact"):
|
161 |
prompt = gr.Textbox(
|
162 |
lines=8,
|
|
|
168 |
container=False,
|
169 |
textarea={'height': '400px'}
|
170 |
)
|
|
|
171 |
run = gr.Button("Generate Images").style(full_width=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
with gr.Row():
|
174 |
with gr.Row():
|
|
|
176 |
|
177 |
with gr.Row():
|
178 |
with gr.Row():
|
179 |
+
output1 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False, show_share_button=False)
|
180 |
+
output2 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False, show_share_button=False)
|
181 |
|
182 |
+
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
|
183 |
+
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
184 |
+
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output2])
|
185 |
+
|
186 |
+
|
187 |
|
188 |
demo.launch(enable_queue=True, inline=True)
|