Spaces:
Runtime error
Runtime error
Delete app-backup.py
Browse files- app-backup.py +0 -117
app-backup.py
DELETED
@@ -1,117 +0,0 @@
|
|
1 |
-
import random
|
2 |
-
import gradio as gr
|
3 |
-
import numpy as np
|
4 |
-
import torch
|
5 |
-
import spaces
|
6 |
-
from diffusers import FluxPipeline
|
7 |
-
from PIL import Image
|
8 |
-
from diffusers.utils import export_to_gif
|
9 |
-
from transformers import pipeline
|
10 |
-
|
11 |
-
HEIGHT = 256
|
12 |
-
WIDTH = 1024
|
13 |
-
MAX_SEED = np.iinfo(np.int32).max
|
14 |
-
|
15 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
-
pipe = FluxPipeline.from_pretrained(
|
17 |
-
"black-forest-labs/FLUX.1-dev",
|
18 |
-
torch_dtype=torch.bfloat16
|
19 |
-
).to(device)
|
20 |
-
|
21 |
-
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
22 |
-
|
23 |
-
def split_image(input_image, num_splits=4):
|
24 |
-
output_images = []
|
25 |
-
for i in range(num_splits):
|
26 |
-
left = i * 256
|
27 |
-
right = (i + 1) * 256
|
28 |
-
box = (left, 0, right, 256)
|
29 |
-
output_images.append(input_image.crop(box))
|
30 |
-
return output_images
|
31 |
-
|
32 |
-
def translate_to_english(text):
|
33 |
-
return translator(text)[0]['translation_text']
|
34 |
-
|
35 |
-
@spaces.GPU()
|
36 |
-
def predict(prompt, seed=42, randomize_seed=False, guidance_scale=5.0, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
|
37 |
-
if any('\u3131' <= char <= '\u318E' or '\uAC00' <= char <= '\uD7A3' for char in prompt):
|
38 |
-
prompt = translate_to_english(prompt)
|
39 |
-
|
40 |
-
prompt_template = f"""
|
41 |
-
A side by side 4 frame image showing consecutive stills from a looped gif moving from left to right. The gif is of {prompt}.
|
42 |
-
"""
|
43 |
-
|
44 |
-
if randomize_seed:
|
45 |
-
seed = random.randint(0, MAX_SEED)
|
46 |
-
|
47 |
-
image = pipe(
|
48 |
-
prompt=prompt_template,
|
49 |
-
guidance_scale=guidance_scale,
|
50 |
-
num_inference_steps=num_inference_steps,
|
51 |
-
num_images_per_prompt=1,
|
52 |
-
generator=torch.Generator("cpu").manual_seed(seed),
|
53 |
-
height=HEIGHT,
|
54 |
-
width=WIDTH
|
55 |
-
).images[0]
|
56 |
-
|
57 |
-
return export_to_gif(split_image(image, 4), "flux.gif", fps=4), image, seed
|
58 |
-
|
59 |
-
css = """
|
60 |
-
footer { visibility: hidden;}
|
61 |
-
"""
|
62 |
-
|
63 |
-
examples = [
|
64 |
-
"๊ณ ์์ด๊ฐ ๊ณต์ค์์ ๋ฐ์ ํ๋๋ ๋ชจ์ต",
|
65 |
-
"ํฌ๋๊ฐ ์๋ฉ์ด๋ฅผ ์ข์ฐ๋ก ํ๋๋ ๋ชจ์ต",
|
66 |
-
"๊ฝ์ด ํผ์ด๋๋ ๊ณผ์ "
|
67 |
-
]
|
68 |
-
|
69 |
-
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
70 |
-
with gr.Column(elem_id="col-container"):
|
71 |
-
with gr.Row():
|
72 |
-
prompt = gr.Text(label="ํ๋กฌํํธ", show_label=False, max_lines=1, placeholder="ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ์ธ์")
|
73 |
-
submit = gr.Button("์ ์ถ", scale=0)
|
74 |
-
output = gr.Image(label="GIF", show_label=False)
|
75 |
-
output_stills = gr.Image(label="์คํธ ์ด๋ฏธ์ง", show_label=False, elem_id="stills")
|
76 |
-
|
77 |
-
with gr.Accordion("๊ณ ๊ธ ์ค์ ", open=False):
|
78 |
-
seed = gr.Slider(
|
79 |
-
label="์๋",
|
80 |
-
minimum=0,
|
81 |
-
maximum=MAX_SEED,
|
82 |
-
step=1,
|
83 |
-
value=0,
|
84 |
-
)
|
85 |
-
randomize_seed = gr.Checkbox(label="์๋ ๋ฌด์์ํ", value=True)
|
86 |
-
with gr.Row():
|
87 |
-
guidance_scale = gr.Slider(
|
88 |
-
label="๊ฐ์ด๋์ค ์ค์ผ์ผ",
|
89 |
-
minimum=1,
|
90 |
-
maximum=15,
|
91 |
-
step=0.1,
|
92 |
-
value=3.5,
|
93 |
-
)
|
94 |
-
num_inference_steps = gr.Slider(
|
95 |
-
label="์ถ๋ก ๋จ๊ณ ์",
|
96 |
-
minimum=1,
|
97 |
-
maximum=50,
|
98 |
-
step=1,
|
99 |
-
value=28,
|
100 |
-
)
|
101 |
-
|
102 |
-
gr.Examples(
|
103 |
-
examples=examples,
|
104 |
-
fn=predict,
|
105 |
-
inputs=[prompt],
|
106 |
-
outputs=[output, output_stills, seed],
|
107 |
-
cache_examples="lazy"
|
108 |
-
)
|
109 |
-
|
110 |
-
gr.on(
|
111 |
-
triggers=[submit.click, prompt.submit],
|
112 |
-
fn=predict,
|
113 |
-
inputs=[prompt, seed, randomize_seed, guidance_scale, num_inference_steps],
|
114 |
-
outputs=[output, output_stills, seed]
|
115 |
-
)
|
116 |
-
|
117 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|