Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,365 +1,214 @@
|
|
1 |
import gradio as gr
|
2 |
-
from PIL import Image
|
3 |
import re
|
4 |
import os
|
5 |
import requests
|
6 |
import uuid
|
7 |
-
import base64
|
|
|
8 |
|
9 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
is_gpu_busy = False
|
17 |
def infer(prompt, negative, scale):
|
18 |
-
|
19 |
-
for
|
20 |
-
if re.search(rf"\b{
|
21 |
-
print(f"
|
22 |
-
print(f"
|
23 |
-
raise gr.Error("
|
24 |
-
|
25 |
-
|
26 |
url = os.getenv('JAX_BACKEND_URL')
|
27 |
if not url:
|
28 |
-
|
|
|
29 |
|
30 |
-
print(f"
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
'guidance_scale': scale
|
35 |
-
}
|
36 |
|
|
|
37 |
try:
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
41 |
|
42 |
-
|
|
|
|
|
43 |
file_path = f"{uuid.uuid4()}.jpg"
|
44 |
with open(file_path, "wb") as f:
|
45 |
-
f.write(base64.b64decode(
|
46 |
images.append(file_path)
|
47 |
-
|
|
|
|
|
|
|
48 |
except requests.exceptions.RequestException as e:
|
49 |
-
|
50 |
-
|
|
|
51 |
except (KeyError, ValueError) as e:
|
52 |
-
|
53 |
-
print(
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
57 |
|
|
|
58 |
css = """
|
59 |
-
/* CSS remains unchanged from your original file */
|
60 |
.gradio-container {
|
61 |
max-width: 768px !important;
|
62 |
-
}
|
63 |
-
.gradio-container {
|
64 |
font-family: 'IBM Plex Sans', sans-serif;
|
65 |
}
|
66 |
.gr-button {
|
67 |
-
color: white;
|
68 |
-
|
69 |
-
background: black;
|
70 |
}
|
71 |
input[type='range'] {
|
72 |
accent-color: black;
|
73 |
}
|
74 |
-
.dark input[type='range'] {
|
75 |
-
accent-color: #dfdfdf;
|
76 |
-
}
|
77 |
-
.container {
|
78 |
-
max-width: 730px;
|
79 |
-
margin: auto;
|
80 |
-
}
|
81 |
#gallery {
|
82 |
min-height: 22rem;
|
83 |
margin-bottom: 15px;
|
84 |
-
|
85 |
-
margin-right: auto;
|
86 |
-
border-bottom-right-radius: .5rem !important;
|
87 |
-
border-bottom-left-radius: .5rem !important;
|
88 |
-
}
|
89 |
-
#gallery>div>.h-full {
|
90 |
-
min-height: 20rem;
|
91 |
-
}
|
92 |
-
.details:hover {
|
93 |
-
text-decoration: underline;
|
94 |
-
}
|
95 |
-
.gr-button {
|
96 |
-
white-space: nowrap;
|
97 |
-
}
|
98 |
-
.gr-button:focus {
|
99 |
-
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
100 |
-
outline: none;
|
101 |
-
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
102 |
-
--tw-border-opacity: 1;
|
103 |
-
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
104 |
-
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
105 |
-
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
106 |
-
--tw-ring-opacity: .5;
|
107 |
}
|
108 |
-
#
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
display: none;
|
118 |
-
margin-bottom: 20px;
|
119 |
}
|
120 |
.footer {
|
121 |
-
margin
|
122 |
-
margin-top: 35px;
|
123 |
text-align: center;
|
124 |
-
border-
|
125 |
-
}
|
126 |
-
.footer>p {
|
127 |
-
font-size: .8rem;
|
128 |
-
display: inline-block;
|
129 |
-
padding: 0 10px;
|
130 |
-
transform: translateY(10px);
|
131 |
-
background: white;
|
132 |
-
}
|
133 |
-
.dark .footer {
|
134 |
-
border-color: #303030;
|
135 |
-
}
|
136 |
-
.dark .footer>p {
|
137 |
-
background: #0b0f19;
|
138 |
-
}
|
139 |
-
.acknowledgments h4{
|
140 |
-
margin: 1.25em 0 .25em 0;
|
141 |
-
font-weight: bold;
|
142 |
-
font-size: 115%;
|
143 |
}
|
144 |
.animate-spin {
|
145 |
animation: spin 1s linear infinite;
|
146 |
}
|
147 |
@keyframes spin {
|
148 |
-
from {
|
149 |
-
|
150 |
-
}
|
151 |
-
to {
|
152 |
-
transform: rotate(360deg);
|
153 |
-
}
|
154 |
-
}
|
155 |
-
#share-btn-container {
|
156 |
-
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
157 |
-
margin-top: 10px;
|
158 |
-
margin-left: auto;
|
159 |
-
}
|
160 |
-
#share-btn-container .styler{
|
161 |
-
background-color: #000000;
|
162 |
-
}
|
163 |
-
#share-btn {
|
164 |
-
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
|
165 |
-
}
|
166 |
-
#share-btn * {
|
167 |
-
all: unset;
|
168 |
}
|
169 |
-
#share-btn-container div:nth-child(-n+2){
|
170 |
-
width: auto !important;
|
171 |
-
min-height: 0px !important;
|
172 |
-
}
|
173 |
-
#share-btn-container .wrap {
|
174 |
-
display: none !important;
|
175 |
-
}
|
176 |
-
.gr-form{
|
177 |
-
flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
|
178 |
-
}
|
179 |
-
#prompt-container{
|
180 |
-
gap: 0;
|
181 |
-
}
|
182 |
-
#prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
|
183 |
-
#component-16{border-top-width: 1px!important;margin-top: 1em}
|
184 |
-
.image_duplication{position: absolute; width: 100px; left: 50px}
|
185 |
-
button{height: 100%}
|
186 |
"""
|
187 |
|
188 |
-
|
189 |
-
|
190 |
examples = [
|
191 |
-
[
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
]
|
196 |
-
[
|
197 |
-
'A pikachu fine dining with a view to the Eiffel Tower',
|
198 |
-
'low quality',
|
199 |
-
9
|
200 |
-
],
|
201 |
-
[
|
202 |
-
'A mecha robot in a favela in expressionist style',
|
203 |
-
'low quality, 3d, photorealistic',
|
204 |
-
9
|
205 |
-
],
|
206 |
-
[
|
207 |
-
'an insect robot preparing a delicious meal',
|
208 |
-
'low quality, illustration',
|
209 |
-
9
|
210 |
-
],
|
211 |
-
[
|
212 |
-
"A small cabin on top of a snowy mountain in the style of Disney, artstation",
|
213 |
-
'low quality, ugly',
|
214 |
-
9
|
215 |
-
],
|
216 |
]
|
217 |
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
<rect x="69" y="115" width="23" height="23" fill="white"></rect>
|
255 |
-
<rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
256 |
-
<rect x="46" y="46" width="23" height="23" fill="black"></rect>
|
257 |
-
<rect x="46" y="115" width="23" height="23" fill="black"></rect>
|
258 |
-
<rect x="46" y="69" width="23" height="23" fill="black"></rect>
|
259 |
-
<rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
|
260 |
-
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
261 |
-
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
262 |
-
</svg>
|
263 |
-
<h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
|
264 |
-
Stable Diffusion 2.1 Demo
|
265 |
-
</h1>
|
266 |
-
</div>
|
267 |
-
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
268 |
-
Stable Diffusion 2.1 is the latest text-to-image model from StabilityAI. <a style="text-decoration: underline;" href="https://huggingface.co/spaces/stabilityai/stable-diffusion-1">Access Stable Diffusion 1 Space here</a><br>For faster generation and API
|
269 |
-
access you can try
|
270 |
-
<a
|
271 |
-
href="http://beta.dreamstudio.ai/"
|
272 |
-
style="text-decoration: underline;"
|
273 |
-
target="_blank"
|
274 |
-
>DreamStudio Beta</a
|
275 |
-
>.</a>
|
276 |
-
</p>
|
277 |
-
</div>
|
278 |
-
"""
|
279 |
)
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
max_lines=1,
|
287 |
-
placeholder="Enter your prompt",
|
288 |
-
elem_id="prompt-text-input",
|
289 |
-
)
|
290 |
-
negative = gr.Textbox(
|
291 |
-
label="Enter your negative prompt",
|
292 |
-
show_label=False,
|
293 |
-
max_lines=1,
|
294 |
-
placeholder="Enter a negative prompt",
|
295 |
-
elem_id="negative-prompt-text-input",
|
296 |
-
)
|
297 |
-
with gr.Column(scale=1, min_width=150):
|
298 |
-
btn = gr.Button("Generate image")
|
299 |
-
|
300 |
-
gallery = gr.Gallery(
|
301 |
-
label="Generated images",
|
302 |
-
show_label=False,
|
303 |
-
elem_id="gallery",
|
304 |
-
columns=[2],
|
305 |
-
height="auto"
|
306 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
-
|
309 |
-
with gr.Group(elem_id="share-btn-container"):
|
310 |
-
community_icon = gr.HTML(community_icon_html)
|
311 |
-
loading_icon = gr.HTML(loading_icon_html)
|
312 |
-
share_button = gr.Button("Share to community", elem_id="share-btn")
|
313 |
-
|
314 |
-
with gr.Accordion("Advanced settings", open=False):
|
315 |
-
guidance_scale = gr.Slider(
|
316 |
-
label="Guidance Scale",
|
317 |
-
minimum=0,
|
318 |
-
maximum=50,
|
319 |
-
value=9,
|
320 |
-
step=0.1
|
321 |
-
)
|
322 |
-
|
323 |
-
ex = gr.Examples(
|
324 |
-
examples=examples,
|
325 |
-
fn=infer,
|
326 |
-
inputs=[text, negative, guidance_scale],
|
327 |
-
outputs=[gallery],
|
328 |
-
cache_examples=False
|
329 |
-
)
|
330 |
-
ex.dataset.headers = [""]
|
331 |
-
|
332 |
-
negative.submit(infer, inputs=[text, negative, guidance_scale], outputs=[gallery])
|
333 |
-
text.submit(infer, inputs=[text, negative, guidance_scale], outputs=[gallery])
|
334 |
-
btn.click(infer, inputs=[text, negative, guidance_scale], outputs=[gallery])
|
335 |
-
|
336 |
-
share_button.click(
|
337 |
-
None,
|
338 |
-
[],
|
339 |
-
[],
|
340 |
-
js=share_js,
|
341 |
-
)
|
342 |
-
gr.HTML(
|
343 |
-
"""
|
344 |
-
<div class="footer">
|
345 |
-
<p>Model by <a href="https://huggingface.co/stabilityai" style="text-decoration: underline;" target="_blank">StabilityAI</a> - backend running JAX on TPUs due to generous support of <a href="https://sites.research.google/trc/about/" style="text-decoration: underline;" target="_blank">Google TRC program</a> - Gradio Demo by 🤗 Hugging Face
|
346 |
-
</p>
|
347 |
-
</div>
|
348 |
-
"""
|
349 |
-
)
|
350 |
-
with gr.Accordion(label="License", open=False):
|
351 |
-
gr.HTML(
|
352 |
-
"""<div class="acknowledgments">
|
353 |
-
<p><h4>LICENSE</h4>
|
354 |
-
The model is licensed with a <a href="https://huggingface.co/stabilityai/stable-diffusion-2/blob/main/LICENSE-MODEL" style="text-decoration: underline;" target="_blank">CreativeML OpenRAIL++</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
|
355 |
-
<p><h4>Biases and content acknowledgment</h4>
|
356 |
-
Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p>
|
357 |
-
</div>
|
358 |
-
"""
|
359 |
-
)
|
360 |
block.launch(
|
361 |
-
show_error=True,
|
362 |
server_name="0.0.0.0",
|
363 |
server_port=7860,
|
364 |
-
|
|
|
365 |
)
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import re
|
3 |
import os
|
4 |
import requests
|
5 |
import uuid
|
6 |
+
import base64
|
7 |
+
import traceback
|
8 |
|
9 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
10 |
|
11 |
+
# সুরক্ষা ফিল্টারের জন্য ওয়ার্ড লিস্ট লোড করুন
|
12 |
+
try:
|
13 |
+
word_list_url = "https://huggingface.co/spaces/stabilityai/stable-diffusion/raw/main/list.txt"
|
14 |
+
response = requests.get(word_list_url, timeout=10)
|
15 |
+
response.raise_for_status()
|
16 |
+
word_list = response.text.splitlines()
|
17 |
+
print(f"সফলভাবে {len(word_list)} টি ফিল্টার শব্দ লোড হয়েছে")
|
18 |
+
except Exception as e:
|
19 |
+
print(f"ওয়ার্ড লিস্ট লোড করতে ব্যর্থ: {str(e)}")
|
20 |
+
word_list = [] # ফিল্টার শব্দ লোড না হলে খালি লিস্ট ব্যবহার করুন
|
21 |
|
|
|
22 |
def infer(prompt, negative, scale):
|
23 |
+
# সুরক্ষা ফিল্টার চেক
|
24 |
+
for filter_word in word_list:
|
25 |
+
if re.search(rf"\b{filter_word}\b", prompt, re.IGNORECASE):
|
26 |
+
print(f"অনুপযুক্ত শব্দ সনাক্ত হয়েছে: {filter_word}")
|
27 |
+
print(f"প্রম্পট: {prompt}")
|
28 |
+
raise gr.Error("অনিরাপদ কন্টেন্ট পাওয়া গেছে! অন্য প্রম্পট ব্যবহার করুন।")
|
29 |
+
|
30 |
+
# ব্যাকএন্ড URL চেক
|
31 |
url = os.getenv('JAX_BACKEND_URL')
|
32 |
if not url:
|
33 |
+
print("ব্যাকএন্ড URL সেট করা নেই!")
|
34 |
+
raise gr.Error("ব্যাকএন্ড সার্ভার কনফিগার করা নেই।")
|
35 |
|
36 |
+
print(f"ব্যাকএন্ড URL: {url}")
|
37 |
+
print(f"প্রম্পট: {prompt}")
|
38 |
+
print(f"নেগেটিভ: {negative}")
|
39 |
+
print(f"স্কেল: {scale}")
|
|
|
|
|
40 |
|
41 |
+
# ব্যাকএন্ডে রিকোয়েস্ট পাঠান
|
42 |
try:
|
43 |
+
payload = {'prompt': prompt, 'negative_prompt': negative, 'guidance_scale': scale}
|
44 |
+
response = requests.post(url, json=payload, timeout=120)
|
45 |
+
response.raise_for_status()
|
46 |
+
response_data = response.json()
|
47 |
|
48 |
+
# ইমেজ প্রসেসিং
|
49 |
+
images = []
|
50 |
+
for img_data in response_data["images"]:
|
51 |
file_path = f"{uuid.uuid4()}.jpg"
|
52 |
with open(file_path, "wb") as f:
|
53 |
+
f.write(base64.b64decode(img_data))
|
54 |
images.append(file_path)
|
55 |
+
|
56 |
+
print(f"{len(images)} টি ইমেজ জেনারেট হয়েছে")
|
57 |
+
return images
|
58 |
+
|
59 |
except requests.exceptions.RequestException as e:
|
60 |
+
error_msg = f"ব্যাকএন্ডে সংযোগ ব্যর্থ: {str(e)}"
|
61 |
+
print(error_msg)
|
62 |
+
raise gr.Error(error_msg)
|
63 |
except (KeyError, ValueError) as e:
|
64 |
+
error_msg = f"ব্যাকএন্ড থেকে ভুল রেসপন্স: {str(e)}"
|
65 |
+
print(error_msg)
|
66 |
+
print(f"রেসপন্স: {response.text[:500]}...")
|
67 |
+
raise gr.Error("ইমেজ জেনারেট করতে ব্যর্থ। আবার চেষ্টা করুন।")
|
68 |
+
except Exception as e:
|
69 |
+
error_msg = f"অপ্রত্যাশিত ত্রুটি: {str(e)}"
|
70 |
+
traceback.print_exc()
|
71 |
+
raise gr.Error(error_msg)
|
72 |
|
73 |
+
# UI স্টাইলিং
|
74 |
css = """
|
|
|
75 |
.gradio-container {
|
76 |
max-width: 768px !important;
|
|
|
|
|
77 |
font-family: 'IBM Plex Sans', sans-serif;
|
78 |
}
|
79 |
.gr-button {
|
80 |
+
color: white !important;
|
81 |
+
background: black !important;
|
|
|
82 |
}
|
83 |
input[type='range'] {
|
84 |
accent-color: black;
|
85 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
#gallery {
|
87 |
min-height: 22rem;
|
88 |
margin-bottom: 15px;
|
89 |
+
border-radius: .5rem !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
}
|
91 |
+
#share-btn-container {
|
92 |
+
display: flex;
|
93 |
+
background-color: #000000;
|
94 |
+
justify-content: center;
|
95 |
+
align-items: center;
|
96 |
+
border-radius: 9999px !important;
|
97 |
+
width: 13rem;
|
98 |
+
margin-top: 10px;
|
99 |
+
margin-left: auto;
|
|
|
|
|
100 |
}
|
101 |
.footer {
|
102 |
+
margin: 35px 0;
|
|
|
103 |
text-align: center;
|
104 |
+
border-top: 1px solid #e5e5e5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
}
|
106 |
.animate-spin {
|
107 |
animation: spin 1s linear infinite;
|
108 |
}
|
109 |
@keyframes spin {
|
110 |
+
from { transform: rotate(0deg); }
|
111 |
+
to { transform: rotate(360deg); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
"""
|
114 |
|
115 |
+
# উদাহরণ প্রম্পট
|
|
|
116 |
examples = [
|
117 |
+
['একটি সুউচ্চ তুষারাবৃত পর্বতের চূড়ায় ছোট কাঠের কুটির', 'নিম্ন গুণগতমান, অস্পষ্ট', 9],
|
118 |
+
['ভবিষ্যতের নগরীতে উড়ন্ত গাড়ি', 'মানুষ, বিকৃত', 9],
|
119 |
+
['সমুদ্রের নীচে সূর্যাস্ত দৃশ্��', 'টেক্সট, লোগো', 9],
|
120 |
+
['ফুলের বাগানে বসে থাকা একটি সিংহ', 'রিয়েলিস্টিক, ফটো', 9],
|
121 |
+
['কাচের গম্বুজের ভিতর মহাকাশ স্টেশন', 'অন্ধকার, ভয়ঙ্কর', 9]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
]
|
123 |
|
124 |
+
# Gradio ব্লক তৈরি
|
125 |
+
with gr.Blocks(css=css) as block:
|
126 |
+
# হেডার
|
127 |
+
gr.HTML("""
|
128 |
+
<div style="text-align: center;">
|
129 |
+
<h1 style="font-weight: 900; margin: 10px 0;">
|
130 |
+
Stable Diffusion 2.1 - বাংলা
|
131 |
+
</h1>
|
132 |
+
<p>
|
133 |
+
টেক্সট থেকে ইমেজ জেনারেটর। আপনার মনের ছবি লিখুন, AI এটা বানিয়ে দেবে!
|
134 |
+
</p>
|
135 |
+
</div>
|
136 |
+
""")
|
137 |
+
|
138 |
+
# ইনপুট সেকশন
|
139 |
+
with gr.Row():
|
140 |
+
with gr.Column(scale=3):
|
141 |
+
prompt_input = gr.Textbox(
|
142 |
+
label="প্রম্পট লিখুন",
|
143 |
+
placeholder="আপনার ইচ্ছামত ছবির বর্ণনা লিখুন...",
|
144 |
+
lines=2
|
145 |
+
)
|
146 |
+
negative_input = gr.Textbox(
|
147 |
+
label="এড়াতে চান এমন বিষয়",
|
148 |
+
placeholder="যেসব বিষয় ছবিতে দেখতে চান না...",
|
149 |
+
lines=1
|
150 |
+
)
|
151 |
+
with gr.Column(scale=1, min_width=150):
|
152 |
+
generate_btn = gr.Button("ইমেজ তৈরি করুন", variant="primary")
|
153 |
+
|
154 |
+
# আউটপুট গ্যালারী
|
155 |
+
gallery = gr.Gallery(
|
156 |
+
label="জেনারেটেড ইমেজসমূহ",
|
157 |
+
columns=[2],
|
158 |
+
height="auto",
|
159 |
+
preview=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
)
|
161 |
+
|
162 |
+
# এডভান্সড সেটিংস
|
163 |
+
with gr.Accordion("উন্নত সেটিংস", open=False):
|
164 |
+
scale_slider = gr.Slider(
|
165 |
+
label="গাইডেন্স স্কেল",
|
166 |
+
minimum=0, maximum=20, value=9, step=0.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
)
|
168 |
+
|
169 |
+
# শেয়ার বাটন
|
170 |
+
with gr.Group():
|
171 |
+
gr.HTML(community_icon_html)
|
172 |
+
gr.HTML(loading_icon_html)
|
173 |
+
share_btn = gr.Button("কমিউনিটিতে শেয়ার করুন")
|
174 |
+
|
175 |
+
# উদাহরণ
|
176 |
+
gr.Examples(
|
177 |
+
examples=examples,
|
178 |
+
inputs=[prompt_input, negative_input, scale_slider],
|
179 |
+
outputs=gallery,
|
180 |
+
fn=infer,
|
181 |
+
cache_examples=False
|
182 |
+
)
|
183 |
+
|
184 |
+
# ইভেন্ট হ্যান্ডলার
|
185 |
+
prompt_input.submit(
|
186 |
+
fn=infer,
|
187 |
+
inputs=[prompt_input, negative_input, scale_slider],
|
188 |
+
outputs=gallery
|
189 |
+
)
|
190 |
+
generate_btn.click(
|
191 |
+
fn=infer,
|
192 |
+
inputs=[prompt_input, negative_input, scale_slider],
|
193 |
+
outputs=gallery,
|
194 |
+
concurrency_limit=3
|
195 |
+
)
|
196 |
+
share_btn.click(None, [], [], js=share_js)
|
197 |
+
|
198 |
+
# ফুটার
|
199 |
+
gr.HTML("""
|
200 |
+
<div class="footer">
|
201 |
+
<p>
|
202 |
+
Powered by <a href="https://huggingface.co/stabilityai">StabilityAI</a>
|
203 |
+
and <a href="https://huggingface.co/spaces">Hugging Face Spaces</a>
|
204 |
+
</p>
|
205 |
+
</div>
|
206 |
+
""")
|
207 |
|
208 |
+
# অ্যাপ্লিকেশন চালু করুন
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
block.launch(
|
|
|
210 |
server_name="0.0.0.0",
|
211 |
server_port=7860,
|
212 |
+
show_error=True,
|
213 |
+
debug=True
|
214 |
)
|