Ashrafb/T444
0
1import gradio as gr2import os3import sys4import random5import string6import time7from queue import Queue8from threading import Thread9 10text_gen = gr.Interface.load("models/Gustavosta/MagicPrompt-Stable-Diffusion")11proc1 = gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")12 13def restart_script_periodically():14 while True:15 random_time = random.randint(540, 600)16 time.sleep(random_time)17 os.execl(sys.executable, sys.executable, *sys.argv)18 19restart_thread = Thread(target=restart_script_periodically, daemon=True)20restart_thread.start()21 22queue = Queue()23queue_threshold = 10024 25def add_random_noise(prompt, noise_level=0.00):26 if noise_level == 0:27 noise_level = 0.0028 percentage_noise = noise_level * 529 num_noise_chars = int(len(prompt) * (percentage_noise / 100))30 noise_indices = random.sample(range(len(prompt)), num_noise_chars)31 prompt_list = list(prompt)32 noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)33 noise_chars.extend(['๐', '๐ฉ', '๐', '๐ค', '๐', '๐ค', '๐ญ', '๐', '๐ท', '๐คฏ', '๐คซ', '๐ฅด', '๐ด', '๐คฉ', '๐ฅณ', '๐', '๐ฉ', '๐คช', '๐', '๐คข', '๐', '๐น', '๐ป', '๐ค', '๐ฝ', '๐', '๐', '๐
', '๐', '๐', '๐', '๐', '๐', '๐', '๐ฎ', 'โค๏ธ', '๐', '๐', '๐', '๐', '๐ถ', '๐ฑ', '๐ญ', '๐น', '๐ฆ', '๐ป', '๐จ', '๐ฏ', '๐ฆ', '๐', '๐ฅ', '๐ง๏ธ', '๐', '๐', '๐ฅ', '๐ด', '๐', '๐บ', '๐ป', '๐ธ', '๐จ', '๐
', '๐', 'โ๏ธ', 'โ๏ธ', 'โ๏ธ', 'โ๏ธ', '๐ค๏ธ', 'โ
๏ธ', '๐ฅ๏ธ', '๐ฆ๏ธ', '๐ง๏ธ', '๐ฉ๏ธ', '๐จ๏ธ', '๐ซ๏ธ', 'โ๏ธ', '๐ฌ๏ธ', '๐จ', '๐ช๏ธ', '๐'])34 for index in noise_indices:35 prompt_list[index] = random.choice(noise_chars)36 return "".join(prompt_list)37 38# Existing code...39 40import uuid # Import the UUID library41 42# Existing code...43 44# Existing code...45 46request_counter = 0 # Global counter to track requests47 48def send_it1(inputs, noise_level, proc=proc1):49 global request_counter50 request_counter += 151 timestamp = f"{time.time()}_{request_counter}"52 prompt_with_noise = add_random_noise(inputs, noise_level) + f" - {timestamp}"53 while queue.qsize() >= queue_threshold:54 time.sleep(2)55 queue.put(prompt_with_noise)56 output = proc(prompt_with_noise)57 return output58import random59 60import random61import time62 63# ... (existing code)64 65import random66import time67 68# ... (existing code)69 70def get_prompts(prompt_text):71 global request_counter72 request_counter += 173 timestamp = f"{time.time()}_{request_counter}"74 75 options = [76 "Cyberpunk android",77 "2060",78 "newyork",79 ", 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"80 ", Editorial Photography, Shot on 70mm lens, Depth of Field, Bokeh, DOF, Tilt Blur, Shutter Speed 1/1000, F/22, 32k, Super-Resolution, award winning,", 81 ", high detail, warm lighting, godrays, vivid, beautiful, trending on artstation, by jordan grimmer, huge scene, grass, art greg rutkowski ", 82 ", highly detailed, digital painting, artstation, illustration, art by artgerm and greg rutkowski and alphonse mucha.", 83 ", 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", 84 ", 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),", 85 ",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)))", 86 87 # Add other prompt options here...88 ]89 90 if prompt_text:91 chosen_option = random.choice(options)92 return text_gen(f"{prompt_text}, {chosen_option} - {timestamp}")93 else:94 return text_gen("", timestamp)95 96 97 98# Existing code...99 100# Existing code...101 102with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{display:none !important;}",) as demo:103 gr.HTML("""104 <div style="text-align: center; max-width: 700px; margin: 0 auto;">105 <div106 style="107 display: inline-flex;108 align-items: center;109 gap: 0.8rem;110 font-size: 1.75rem;111 "112 >113 <div>114 <h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">115 Dreamlike Photoreal 2.0116 </h1>117 </div>118 </div>119 </div>120 <p style="margin-bottom: 10px; font-size: 96%">121 Noise Level: Controls how much randomness is added to the input before it is sent to the model. Higher noise level produces more diverse outputs, while lower noise level produces similar outputs,122 123 </p>124 125 </div>126 """)127 128 with gr.Column(elem_id="col-container"):129 with gr.Row(variant="compact"):130 input_text = gr.Textbox(131 lines=8,132 label="Short Prompt",133 show_label=False,134 max_lines=10,135 placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!",136 ).style(137 container=False,138 textarea={'height': '400px'}139 )140 see_prompts = gr.Button("โจ Magic Prompt โจ").style(full_width=False)141 142 with gr.Row(variant="compact"):143 prompt = gr.Textbox(144 lines=8,145 label="Enter your prompt",146 show_label=False,147 max_lines=10,148 placeholder="Full Prompt",149 ).style(150 container=False,151 textarea={'height': '400px'}152 )153 run = gr.Button("Generate Images").style(full_width=False)154 155 with gr.Row():156 with gr.Row():157 noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")158 159 with gr.Row():160 with gr.Row():161 output1 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False, show_share_button=False)162 output2 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False, show_share_button=False)163 164 see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)165 run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])166 run.click(send_it1, inputs=[prompt, noise_level], outputs=[output2])167 gr.HTML("""168 <div class="footer" style="margin-bottom: 45px;169 margin-top: 35px;170 text-align: center;171 border-bottom: 1px solid #e5e5e5" 172>173 <p style="font-size: .8rem;174 display: inline-block;175 padding: 0 10px;176 transform: translateY(10px);177 background: white" > Demo for <a href="https://huggingface.co/dreamlike-art/dreamlike-photoreal-2.0">Dreamlike Photoreal 2.0</a> Stable Diffusion model178 </p>179 </div>180 <div class="acknowledgments" style="margin: 1.25em 0 .25em 0;181 182 font-size: 96%">183 <p> โค๏ธUnleash your creative side and generate mesmerizing images with just a few clicks! Enter a spark of inspiration in the "Basic Idea" text box and click the "Magic Prompt" button to elevate it to a polished masterpiece. Make any final tweaks in the "Full Prompt" box and hit the "Generate Images" button to watch your vision come to life. Experiment with the "Noise Level" for a diverse range of outputs, from similar to wildly unique. Let the fun begin!โค๏ธ184 </p>185 </div>186 """)187 188 189 demo.launch(enable_queue=True, inline=True)190 