File size: 2,253 Bytes
7a1db81
 
 
 
 
 
 
 
 
e39414c
7a1db81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
import sys
import random
import string
import time
from queue import Queue
from threading import Thread

proc1 = gr.Interface.load("models/playgroundai/playground-v2-1024px-aesthetic")

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


import uuid  # Import the UUID library

# Existing code...

# Existing code...

request_counter = 0  # Global counter to track requests

# Modify your send_it1 function to handle any errors generically
def send_it1(inputs, proc=proc1):
    global request_counter
    

    request_counter += 1
    timestamp = f"{time.time()}_{request_counter}"
    prompt_with_noise = (inputs) + 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=".gradio-container {background-color: #FDF5E6;} .dark .gradio-container {background-color: black;} footer{display:none !important;}",) as demo:
    with gr.Column(elem_id="col-container"):
        with gr.Row(variant="compact"):
            input_text = gr.Textbox(
                lines=8,
                label="Enter your prompt",
                show_label=False,
                max_lines=10,
                placeholder="Enter your text prompt here",
            ).style(
                container=False,
                textarea={'height': '400px'}
            )
            run = gr.Button("Generate Image").style(full_width=False)

        with gr.Row():
            with gr.Row():
                output1 = gr.Image(label="", show_label=False, show_share_button=False)
                
        run.click(send_it1, inputs=[input_text], outputs=[output1])

    demo.launch(enable_queue=True, inline=True)