Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
import io
|
2 |
import random
|
3 |
import time
|
|
|
4 |
from urllib.parse import quote
|
5 |
|
6 |
import gradio as gr
|
@@ -10,7 +10,7 @@ from PIL import Image
|
|
10 |
MAX_SEED = 2 ** 31 - 1
|
11 |
session = requests.Session()
|
12 |
|
13 |
-
def
|
14 |
for i in range(retries + 1):
|
15 |
try:
|
16 |
response = session.get(*args, **kwargs)
|
@@ -24,13 +24,6 @@ def _fetch_url(*args, retries=5, **kwargs):
|
|
24 |
return None
|
25 |
return None
|
26 |
|
27 |
-
def add_to_gallery(image, gallery=None):
|
28 |
-
if gallery is None:
|
29 |
-
gallery = []
|
30 |
-
if image is not None:
|
31 |
-
gallery = gallery + [image]
|
32 |
-
return gallery
|
33 |
-
|
34 |
def generate(
|
35 |
prompt,
|
36 |
seed=None,
|
@@ -41,14 +34,19 @@ def generate(
|
|
41 |
if seed is None or randomize_seed:
|
42 |
seed = random.randint(0, MAX_SEED)
|
43 |
url = f"https://pollinations.ai/p/{quote(prompt)}?nologo=true&private=true"
|
44 |
-
params = dict(
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
46 |
if image:
|
47 |
-
return Image.open(
|
48 |
return None
|
49 |
|
50 |
with gr.Blocks(
|
51 |
-
title="Text-to-
|
52 |
css="footer {display: none !important}",
|
53 |
theme=gr.themes.Base(
|
54 |
primary_hue="red",
|
@@ -56,7 +54,7 @@ with gr.Blocks(
|
|
56 |
neutral_hue="neutral"
|
57 |
)
|
58 |
) as app:
|
59 |
-
gr.Markdown("# Text-to-Image
|
60 |
with gr.Tab("π¨ Generate"):
|
61 |
result = gr.Image(
|
62 |
label="Image",
|
@@ -73,7 +71,7 @@ with gr.Blocks(
|
|
73 |
container=False
|
74 |
)
|
75 |
btn = gr.Button("Generate", variant="primary")
|
76 |
-
|
77 |
with gr.Tab("βοΈ Settings"):
|
78 |
with gr.Row():
|
79 |
seed = gr.Slider(
|
@@ -109,13 +107,20 @@ with gr.Blocks(
|
|
109 |
interactive=False
|
110 |
)
|
111 |
|
112 |
-
with gr.Accordion("βΉοΈ About
|
113 |
gr.Markdown(f"""
|
114 |
* Created by [π cherry-ghosts community](https://hf.co/cherry-ghosts)
|
115 |
* Powered by [π Pollinations](https://pollinations.ai) | [GitHub](https://github.com/pollinations/pollinations)
|
116 |
* Running on [Gradio](https://www.gradio.app) v{gr.__version__}
|
117 |
""")
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
btn.click(
|
120 |
generate,
|
121 |
inputs=[prompt, seed, randomize_seed, width, height],
|
|
|
|
|
1 |
import random
|
2 |
import time
|
3 |
+
from io import BytesIO
|
4 |
from urllib.parse import quote
|
5 |
|
6 |
import gradio as gr
|
|
|
10 |
MAX_SEED = 2 ** 31 - 1
|
11 |
session = requests.Session()
|
12 |
|
13 |
+
def _fetch(*args, retries=5, **kwargs):
|
14 |
for i in range(retries + 1):
|
15 |
try:
|
16 |
response = session.get(*args, **kwargs)
|
|
|
24 |
return None
|
25 |
return None
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def generate(
|
28 |
prompt,
|
29 |
seed=None,
|
|
|
34 |
if seed is None or randomize_seed:
|
35 |
seed = random.randint(0, MAX_SEED)
|
36 |
url = f"https://pollinations.ai/p/{quote(prompt)}?nologo=true&private=true"
|
37 |
+
params = dict(
|
38 |
+
prompt=prompt,
|
39 |
+
seed=seed,
|
40 |
+
width=width,
|
41 |
+
height=height
|
42 |
+
)
|
43 |
+
image = _fetch(url, params=params)
|
44 |
if image:
|
45 |
+
return Image.open(BytesIO(image))
|
46 |
return None
|
47 |
|
48 |
with gr.Blocks(
|
49 |
+
title="Text-to-Image",
|
50 |
css="footer {display: none !important}",
|
51 |
theme=gr.themes.Base(
|
52 |
primary_hue="red",
|
|
|
54 |
neutral_hue="neutral"
|
55 |
)
|
56 |
) as app:
|
57 |
+
gr.Markdown("# Text-to-Image")
|
58 |
with gr.Tab("π¨ Generate"):
|
59 |
result = gr.Image(
|
60 |
label="Image",
|
|
|
71 |
container=False
|
72 |
)
|
73 |
btn = gr.Button("Generate", variant="primary")
|
74 |
+
|
75 |
with gr.Tab("βοΈ Settings"):
|
76 |
with gr.Row():
|
77 |
seed = gr.Slider(
|
|
|
107 |
interactive=False
|
108 |
)
|
109 |
|
110 |
+
with gr.Accordion("βΉοΈ About", open=False):
|
111 |
gr.Markdown(f"""
|
112 |
* Created by [π cherry-ghosts community](https://hf.co/cherry-ghosts)
|
113 |
* Powered by [π Pollinations](https://pollinations.ai) | [GitHub](https://github.com/pollinations/pollinations)
|
114 |
* Running on [Gradio](https://www.gradio.app) v{gr.__version__}
|
115 |
""")
|
116 |
|
117 |
+
def add_to_gallery(img, gallery):
|
118 |
+
if gallery is None:
|
119 |
+
gallery = []
|
120 |
+
if img is not None:
|
121 |
+
gallery = gallery + [img]
|
122 |
+
return gallery
|
123 |
+
|
124 |
btn.click(
|
125 |
generate,
|
126 |
inputs=[prompt, seed, randomize_seed, width, height],
|