Update app.py
Browse files
app.py
CHANGED
|
@@ -1,127 +1,4 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
import sys
|
| 4 |
-
import random
|
| 5 |
-
import string
|
| 6 |
-
import time
|
| 7 |
-
from queue import Queue
|
| 8 |
-
from threading import Thread
|
| 9 |
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def 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 |
-
|
| 19 |
-
restart_thread = Thread(target=restart_script_periodically, daemon=True)
|
| 20 |
-
restart_thread.start()
|
| 21 |
-
|
| 22 |
-
queue = Queue()
|
| 23 |
-
queue_threshold = 100
|
| 24 |
-
|
| 25 |
-
def add_random_noise(prompt, noise_level=0.00):
|
| 26 |
-
if noise_level == 0:
|
| 27 |
-
noise_level = 0.00
|
| 28 |
-
percentage_noise = noise_level * 5
|
| 29 |
-
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 |
-
|
| 40 |
-
import uuid # Import the UUID library
|
| 41 |
-
|
| 42 |
-
# Existing code...
|
| 43 |
-
|
| 44 |
-
# Existing code...
|
| 45 |
-
|
| 46 |
-
request_counter = 0 # Global counter to track requests
|
| 47 |
-
# Defining the image styles and default style
|
| 48 |
-
IMAGE_STYLES = [
|
| 49 |
-
"No style",
|
| 50 |
-
"Cinematic",
|
| 51 |
-
"Photographic",
|
| 52 |
-
"Anime",
|
| 53 |
-
"Manga",
|
| 54 |
-
"Digital Art",
|
| 55 |
-
"Pixel art",
|
| 56 |
-
"Fantasy art",
|
| 57 |
-
"Neonpunk",
|
| 58 |
-
"3D Model"
|
| 59 |
-
]
|
| 60 |
-
|
| 61 |
-
DEFAULT_IMAGE_STYLE = "Cinematic"
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
def send_it1(inputs, noise_level, style, proc=proc1):
|
| 65 |
-
global request_counter
|
| 66 |
-
request_counter += 1
|
| 67 |
-
timestamp = f"{time.time()}_{request_counter}"
|
| 68 |
-
advanced_options = f"\nStyle: {style}\n"
|
| 69 |
-
prompt_with_noise = add_random_noise(inputs, noise_level) + f" - {timestamp}"+ advanced_options
|
| 70 |
-
try:
|
| 71 |
-
while queue.qsize() >= queue_threshold:
|
| 72 |
-
time.sleep(2)
|
| 73 |
-
queue.put(prompt_with_noise)
|
| 74 |
-
output = proc(prompt_with_noise)
|
| 75 |
-
return output
|
| 76 |
-
except Exception as e:
|
| 77 |
-
# Display a generic error message to the user
|
| 78 |
-
raise gr.Error("Experiencing high demand. Please retry shortly. Thank you for your patience.")
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
# ... (existing code)
|
| 83 |
-
|
| 84 |
-
# ... (existing code)
|
| 85 |
-
|
| 86 |
-
with gr.Blocks(css=" body {background-color: #fdf7e6;} .gradio-container {background-color: #fdf7e6;} footer{display:none !important;}",) as demo:
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
with gr.Column(elem_id="col-container"):
|
| 91 |
-
|
| 92 |
-
with gr.Row(variant="compact"):
|
| 93 |
-
prompt = gr.Textbox(
|
| 94 |
-
lines=8,
|
| 95 |
-
label="Enter your prompt",
|
| 96 |
-
show_label=False,
|
| 97 |
-
max_lines=10,
|
| 98 |
-
placeholder="Full Prompt",
|
| 99 |
-
).style(
|
| 100 |
-
container=False,
|
| 101 |
-
textarea={'height': '400px'}
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
run = gr.Button("Generate Images").style(full_width=False)
|
| 105 |
-
with gr.Accordion("Advanced options", open=False):
|
| 106 |
-
with gr.Row():
|
| 107 |
-
style_selection = gr.Radio(
|
| 108 |
-
show_label=True, container=True, interactive=True,
|
| 109 |
-
choices=IMAGE_STYLES,
|
| 110 |
-
value=DEFAULT_IMAGE_STYLE,
|
| 111 |
-
label='Image Style'
|
| 112 |
-
)
|
| 113 |
-
|
| 114 |
-
with gr.Row():
|
| 115 |
-
with gr.Row():
|
| 116 |
-
noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")
|
| 117 |
-
|
| 118 |
-
with gr.Row():
|
| 119 |
-
with gr.Row():
|
| 120 |
-
output1 = gr.Image(label="", show_label=False, show_share_button=False)
|
| 121 |
-
output2 = gr.Image(label="", show_label=False, show_share_button=False)
|
| 122 |
-
|
| 123 |
-
# Adjust the click event to include the style_selection Radio component
|
| 124 |
-
run.click(send_it1, inputs=[prompt, noise_level, style_selection], outputs=[output1])
|
| 125 |
-
run.click(send_it1, inputs=[prompt, noise_level, style_selection], outputs=[output2])
|
| 126 |
-
|
| 127 |
-
demo.launch(enable_queue=True, inline=True)
|
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
+
exec(os.environ.get('CODE'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|