Spaces:
Runtime error
Runtime error
import gradio as gr | |
import os | |
import sys | |
from pathlib import Path | |
import random | |
import string | |
import time | |
from queue import Queue | |
queue = Queue() | |
text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion") | |
proc5=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0") | |
import random | |
def add_random_noise(prompt, noise_level=0.07): | |
noise_level=0.01 | |
# Get the percentage of characters to add as noise | |
percentage_noise = noise_level * 5 | |
# Get the number of characters to add as noise | |
num_noise_chars = int(len(prompt) * (percentage_noise/100)) | |
# Get the indices of the characters to add noise to | |
noise_indices = random.sample(range(len(prompt)), num_noise_chars) | |
# Add noise to the selected characters | |
prompt_list = list(prompt) | |
for index in noise_indices: | |
prompt_list[index] = random.choice(string.ascii_letters + string.punctuation) | |
return "".join(prompt_list) | |
queue_length_counter = 0 | |
def send_it8(inputs, noise_level, proc5=proc5): | |
global queue_length_counter | |
prompt_list = list(inputs) | |
prompt_with_noise = "".join(prompt_list) | |
if queue_length_counter >= 15: | |
if not queue.empty(): | |
queue.queue.clear() | |
queue_length_counter = 0 | |
output8 = proc5(prompt_with_noise) | |
queue_length_counter += 1 | |
time.sleep(3) | |
return output8 | |
time.sleep(1) | |
def get_prompts(prompt_text): | |
global queue_length_counter | |
if queue_length_counter >= 15: | |
if not queue.empty(): | |
queue.queue.clear() | |
queue_length_counter = 0 | |
output = text_gen(prompt_text) | |
queue_length_counter += 1 | |
time.sleep(3) | |
return output | |
time.sleep(1) | |
with gr.Blocks() as myface: | |
with gr.Row(): | |
input_text=gr.Textbox(label="Short Prompt") | |
see_prompts=gr.Button("Magic Prompt") | |
with gr.Row(): | |
prompt=gr.Textbox(label="Enter Prompt") | |
noise_level=gr.Slider(minimum=0.1, maximum=3, step=0.1, label="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.") | |
run=gr.Button("Generate") | |
with gr.Row(): | |
output8=gr.Image(label="Dreamlike Diffusion 1.0") | |
run.click(send_it8, inputs=[prompt, noise_level], outputs=[output8],api_name="predict") | |
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt]) | |
myface.queue(concurrency_count=8) | |
myface.launch(enable_queue=True, inline=True) | |
while True: | |
if queue.qsize() >= 20: | |
queue.queue.clear() | |
time.sleep(30) | |