Spaces:
Runtime error
Runtime error
File size: 2,576 Bytes
c8f4a17 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
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):
# 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_with_noise = add_random_noise(inputs, noise_level)
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_it1, inputs=[prompt, noise_level], outputs=[output1])
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)
|