import gradio as gr import os import sys import random import string import time from queue import Queue from threading import Thread text_gen = gr.load(name="spaces/Ashrafb/MagicPrompt-Stable-Diffusiongust") proc1 = gr.Interface.load("models/runwayml/stable-diffusion-v1-5") def get_prompts(prompt_text): return text_gen(prompt_text) def restart_script_periodically(): while True: random_time = random.randint(540, 600) time.sleep(random_time) os.execl(sys.executable, sys.executable, *sys.argv) restart_thread = Thread(target=restart_script_periodically, daemon=True) restart_thread.start() queue = Queue() queue_threshold = 100 def add_random_noise(prompt, noise_level=0.00): if noise_level == 0: noise_level = 0.00 percentage_noise = noise_level * 5 num_noise_chars = int(len(prompt) * (percentage_noise / 100)) noise_indices = random.sample(range(len(prompt)), num_noise_chars) prompt_list = list(prompt) noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits) noise_chars.extend(['ð', 'ðĐ', 'ð', 'ðĪ', 'ð', 'ðĪ', 'ð', 'ð', 'ð·', 'ðĪŊ', 'ðĪŦ', 'ðĨī', 'ðī', 'ðĪĐ', 'ðĨģ', 'ð', 'ðĐ', 'ðĪŠ', 'ð', 'ðĪĒ', 'ð', 'ðđ', 'ðŧ', 'ðĪ', 'ð―', 'ð', 'ð', 'ð ', 'ð', 'ð', 'ð', 'ð', 'ð', 'ð', 'ðŪ', 'âĪïļ', 'ð', 'ð', 'ð', 'ð', 'ðķ', 'ðą', 'ð', 'ðđ', 'ðĶ', 'ðŧ', 'ðĻ', 'ðŊ', 'ðĶ', 'ð', 'ðĨ', 'ð§ïļ', 'ð', 'ð', 'ðĨ', 'ðī', 'ð', 'ðš', 'ðŧ', 'ðļ', 'ðĻ', 'ð ', 'ð', 'âïļ', 'âïļ', 'âïļ', 'âïļ', 'ðĪïļ', 'â ïļ', 'ðĨïļ', 'ðĶïļ', 'ð§ïļ', 'ðĐïļ', 'ðĻïļ', 'ðŦïļ', 'âïļ', 'ðŽïļ', 'ðĻ', 'ðŠïļ', 'ð']) for index in noise_indices: prompt_list[index] = random.choice(noise_chars) return "".join(prompt_list) # Existing code... import uuid # Import the UUID library # Existing code... # Existing code... request_counter = 0 # Global counter to track requests def send_it1(inputs, noise_level, proc=proc1): global request_counter request_counter += 1 timestamp = f"{time.time()}_{request_counter}" prompt_with_noise = add_random_noise(inputs, noise_level) + f" - {timestamp}" try: while queue.qsize() >= queue_threshold: time.sleep(2) queue.put(prompt_with_noise) output = proc(prompt_with_noise) return output except Exception as e: # Display a generic error message to the user raise gr.Error("Experiencing high demand. Please retry shortly. Thank you for your patience.") with gr.Blocks(css="footer{display:none !important;}",) as demo: gr.HTML("""
This Space prettifies your prompt using MagicPrompt and then runs it through Stable Diffusion to create aesthetically pleasing images. Simply enter a few concepts and let it improve your prompt. You can then diffuse the prompt.