Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,12 @@
|
|
1 |
import random
|
2 |
-
import time
|
3 |
-
from io import BytesIO
|
4 |
-
from urllib.parse import quote
|
5 |
|
6 |
-
from datasets import load_dataset
|
7 |
import gradio as gr
|
8 |
-
import
|
9 |
-
|
|
|
10 |
|
11 |
MAX_SEED = 2 ** 31 - 1
|
12 |
-
|
13 |
-
|
14 |
-
def _fetch(*args, retries=5, **kwargs):
|
15 |
-
for i in range(retries + 1):
|
16 |
-
try:
|
17 |
-
response = session.get(*args, **kwargs)
|
18 |
-
response.raise_for_status()
|
19 |
-
return response.content
|
20 |
-
except requests.RequestException:
|
21 |
-
if response.status_code in {429, 500, 502, 503, 504}:
|
22 |
-
delay = min(2 ** i, 60)
|
23 |
-
time.sleep(delay)
|
24 |
-
else:
|
25 |
-
return None
|
26 |
-
return None
|
27 |
|
28 |
def load_examples():
|
29 |
ds = load_dataset("k-mktr/improved-flux-prompts", split="train")
|
@@ -38,20 +21,15 @@ def generate(
|
|
38 |
):
|
39 |
if seed is None or randomize_seed:
|
40 |
seed = random.randint(0, MAX_SEED)
|
41 |
-
|
42 |
-
params = dict(
|
43 |
prompt=prompt,
|
44 |
seed=seed,
|
45 |
width=width,
|
46 |
height=height
|
47 |
)
|
48 |
-
image = _fetch(url, params=params)
|
49 |
-
if image:
|
50 |
-
return Image.open(BytesIO(image))
|
51 |
-
return None
|
52 |
|
53 |
with gr.Blocks(
|
54 |
-
title="Text-to-Image",
|
55 |
css="footer {display: none !important}",
|
56 |
theme=gr.themes.Base(
|
57 |
primary_hue="red",
|
@@ -83,7 +61,7 @@ with gr.Blocks(
|
|
83 |
inputs=[prompt],
|
84 |
examples_per_page=2
|
85 |
)
|
86 |
-
randomize_btn = gr.Button("
|
87 |
|
88 |
with gr.Tab("⚙️ Settings"):
|
89 |
with gr.Row():
|
@@ -119,7 +97,7 @@ with gr.Blocks(
|
|
119 |
format="jpeg",
|
120 |
interactive=False
|
121 |
)
|
122 |
-
clear_btn = gr.Button("
|
123 |
|
124 |
with gr.Accordion("ℹ️ About", open=False):
|
125 |
gr.Markdown(f"""
|
|
|
1 |
import random
|
|
|
|
|
|
|
2 |
|
|
|
3 |
import gradio as gr
|
4 |
+
from datasets import load_dataset
|
5 |
+
|
6 |
+
from client import Inference
|
7 |
|
8 |
MAX_SEED = 2 ** 31 - 1
|
9 |
+
client = Inference()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def load_examples():
|
12 |
ds = load_dataset("k-mktr/improved-flux-prompts", split="train")
|
|
|
21 |
):
|
22 |
if seed is None or randomize_seed:
|
23 |
seed = random.randint(0, MAX_SEED)
|
24 |
+
return client(
|
|
|
25 |
prompt=prompt,
|
26 |
seed=seed,
|
27 |
width=width,
|
28 |
height=height
|
29 |
)
|
|
|
|
|
|
|
|
|
30 |
|
31 |
with gr.Blocks(
|
32 |
+
title="🎨 Text-to-Image",
|
33 |
css="footer {display: none !important}",
|
34 |
theme=gr.themes.Base(
|
35 |
primary_hue="red",
|
|
|
61 |
inputs=[prompt],
|
62 |
examples_per_page=2
|
63 |
)
|
64 |
+
randomize_btn = gr.Button("See more")
|
65 |
|
66 |
with gr.Tab("⚙️ Settings"):
|
67 |
with gr.Row():
|
|
|
97 |
format="jpeg",
|
98 |
interactive=False
|
99 |
)
|
100 |
+
clear_btn = gr.Button("Clear")
|
101 |
|
102 |
with gr.Accordion("ℹ️ About", open=False):
|
103 |
gr.Markdown(f"""
|