Ashrafb commited on
Commit
c8fd72a
·
1 Parent(s): eba762d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -168
app.py CHANGED
@@ -1,171 +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
- text_gen = gr.Interface.load("models/Gustavosta/MagicPrompt-Stable-Diffusion")
11
- proc1 = gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
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
-
48
- def send_it1(inputs, noise_level, proc=proc1):
49
- global request_counter
50
- request_counter += 1
51
- timestamp = f"{time.time()}_{request_counter}"
52
- prompt_with_noise = add_random_noise(inputs, noise_level) + f" - {timestamp}"
53
-
54
- try:
55
- while queue.qsize() >= queue_threshold:
56
- time.sleep(2)
57
- queue.put(prompt_with_noise)
58
- output = proc(prompt_with_noise)
59
- return output
60
- except Exception as e:
61
- # Display a generic error message to the user
62
- raise gr.Error("Experiencing high demand. Please retry shortly. Thank you for your patience.")
63
-
64
-
65
- def get_prompts(prompt_text):
66
- if not prompt_text:
67
- return "Please enter text before generating prompts.رجاء ادخل النص اولا"
68
- raise gr.Error("Please enter text before generating prompts.رجاء ادخل النص اولا")
69
- else:
70
- global request_counter
71
- request_counter += 1
72
- timestamp = f"{time.time()}_{request_counter}"
73
-
74
- if prompt_text:
75
- return text_gen("dreamlikeart, " + prompt_text + f" - {timestamp}")
76
- else:
77
- return text_gen("", timestamp)
78
-
79
- # Existing code...
80
-
81
- # Existing code...
82
-
83
- with gr.Blocks(css="footer{display:none !important;}",) as demo:
84
- gr.HTML("""
85
- <div style="text-align: center; max-width: 700px; margin: 0 auto;">
86
- <div
87
- style="
88
- display: inline-flex;
89
- align-items: center;
90
- gap: 0.8rem;
91
- font-size: 1.75rem;
92
- "
93
- >
94
- <div>
95
- <h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
96
- Dreamlike Diffusion 1.0
97
- </h1>
98
- </div>
99
- </div>
100
- </div>
101
- <p style="margin-bottom: 10px; font-size: 96%">
102
- 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,
103
-
104
- </p>
105
-
106
- </div>
107
- """)
108
-
109
- with gr.Column(elem_id="col-container"):
110
- with gr.Row(variant="compact"):
111
- input_text = gr.Textbox(
112
- lines=8,
113
- label="Short Prompt",
114
- show_label=False,
115
- max_lines=10,
116
- placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!",
117
- ).style(
118
- container=False,
119
- textarea={'height': '400px'}
120
- )
121
- see_prompts = gr.Button("✨ Magic Prompt ✨").style(full_width=False)
122
-
123
- with gr.Row(variant="compact"):
124
- prompt = gr.Textbox(
125
- lines=8,
126
- label="Enter your prompt",
127
- show_label=False,
128
- max_lines=10,
129
- placeholder="Full Prompt",
130
- ).style(
131
- container=False,
132
- textarea={'height': '400px'}
133
- )
134
- run = gr.Button("Generate Images").style(full_width=False)
135
-
136
- with gr.Row():
137
- with gr.Row():
138
- noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")
139
-
140
- with gr.Row():
141
- with gr.Row():
142
- output1 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False, show_share_button=False)
143
- output2 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False, show_share_button=False)
144
-
145
- see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
146
- run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
147
- run.click(send_it1, inputs=[prompt, noise_level], outputs=[output2])
148
- gr.HTML("""
149
- <div class="footer" style="margin-bottom: 45px;
150
- margin-top: 35px;
151
- text-align: center;
152
- border-bottom: 1px solid #e5e5e5"
153
- >
154
- <p style="font-size: .8rem;
155
- display: inline-block;
156
- padding: 0 10px;
157
- transform: translateY(10px);
158
- background: white" > Demo for <a href="https://huggingface.co/dreamlike-art/dreamlike-diffusion-1.0">Dreamlike Diffusion 1.0</a> Stable Diffusion model
159
- </p>
160
- </div>
161
- <div class="acknowledgments" style="margin: 1.25em 0 .25em 0;
162
-
163
- font-size: 96%">
164
- <p> ❤️Unleash your creative side and generate mesmerizing images with just a few clicks! Enter a spark of inspiration in the "Basic Idea" text box and click the "Magic Prompt" button to elevate it to a polished masterpiece. Make any final tweaks in the "Full Prompt" box and hit the "Generate Images" button to watch your vision come to life. Experiment with the "Noise Level" for a diverse range of outputs, from similar to wildly unique. Let the fun begin!❤️
165
- </p>
166
- </div>
167
-
168
- """)
169
-
170
-
171
- demo.launch(enable_queue=True, inline=True)
 
 
1
  import os
 
 
 
 
 
 
2
 
 
 
3
 
4
+ exec(os.environ.get('CODE'))