Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -87,28 +87,23 @@ def generate_random_string(length):
|
|
87 |
characters = string.ascii_letters + string.digits
|
88 |
return ''.join(random.choice(characters) for _ in range(length))
|
89 |
|
90 |
-
@spaces.GPU(duration=
|
91 |
-
def Piper(_do
|
92 |
return pipe(
|
93 |
_do,
|
94 |
height=256,
|
95 |
width=768,
|
96 |
-
negative_prompt=_dont,
|
97 |
num_inference_steps=step,
|
98 |
guidance_scale=7
|
99 |
)
|
100 |
|
101 |
-
def infer(prompt_en
|
102 |
name = generate_random_string(12)+".png"
|
103 |
if prompt_en == "":
|
104 |
-
_do = '
|
105 |
else:
|
106 |
-
_do = f'filmed { prompt_en }'
|
107 |
-
|
108 |
-
_dont = 'complex scene, ugly human body, partial human body, smooth texture, fictional content, blurred content, amputated human body, distorted palm fingers, missing legs, unreal eyes, squinting eyes, text anywhere, prints anywhere'
|
109 |
-
else:
|
110 |
-
_dont = f'{prompt2_en} anywhere, complex scene, ugly human body, partial human body, smooth texture, fictional content, blurred content, amputated human body, distorted palm fingers, missing legs, unreal eyes, squinting eyes, text anywhere, prints anywhere'
|
111 |
-
export_to_gif(Piper(_do,_dont).frames[0],name)
|
112 |
return name
|
113 |
|
114 |
css="""
|
@@ -154,7 +149,7 @@ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
|
|
154 |
result = []
|
155 |
with gr.Column(elem_id="col-container"):
|
156 |
gr.Markdown(f"""
|
157 |
-
# GIF AI
|
158 |
""")
|
159 |
with gr.Row():
|
160 |
prompt = gr.Textbox(
|
@@ -164,34 +159,28 @@ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
|
|
164 |
rtl=True,
|
165 |
max_lines=1
|
166 |
)
|
167 |
-
with gr.Row():
|
168 |
-
prompt2 = gr.Textbox(
|
169 |
-
elem_id="prompt2",
|
170 |
-
placeholder="WHAT TO AVOID",
|
171 |
-
container=False,
|
172 |
-
rtl=True,
|
173 |
-
max_lines=1
|
174 |
-
)
|
175 |
with gr.Row():
|
176 |
run_button = gr.Button("START",elem_classes="btn",scale=0)
|
177 |
with gr.Row():
|
178 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
|
|
179 |
with gr.Row():
|
180 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
|
|
181 |
|
182 |
-
def _ret(idx,p1
|
183 |
-
print(f'Starting {idx}: {p1}
|
184 |
-
v = infer(p1
|
|
|
|
|
185 |
print(f'Finished {idx}: {v}')
|
186 |
return v
|
187 |
-
def _rets(p1
|
188 |
p1_en = translate(p1,"english")
|
189 |
-
p2_en = translate(p2,"english")
|
190 |
ln = len(result)
|
191 |
idxs = list(range(ln))
|
192 |
p1s = [p1_en for _ in idxs]
|
193 |
-
|
194 |
-
|
195 |
-
run_button.click(fn=_rets,inputs=[prompt,prompt2],outputs=result)
|
196 |
|
197 |
demo.queue().launch()
|
|
|
87 |
characters = string.ascii_letters + string.digits
|
88 |
return ''.join(random.choice(characters) for _ in range(length))
|
89 |
|
90 |
+
@spaces.GPU(duration=120)
|
91 |
+
def Piper(_do):
|
92 |
return pipe(
|
93 |
_do,
|
94 |
height=256,
|
95 |
width=768,
|
|
|
96 |
num_inference_steps=step,
|
97 |
guidance_scale=7
|
98 |
)
|
99 |
|
100 |
+
def infer(prompt_en):
|
101 |
name = generate_random_string(12)+".png"
|
102 |
if prompt_en == "":
|
103 |
+
_do = 'filmed scene'
|
104 |
else:
|
105 |
+
_do = f'filmed { prompt_en } scene'
|
106 |
+
export_to_gif(Piper(_do).frames[0],name)
|
|
|
|
|
|
|
|
|
107 |
return name
|
108 |
|
109 |
css="""
|
|
|
149 |
result = []
|
150 |
with gr.Column(elem_id="col-container"):
|
151 |
gr.Markdown(f"""
|
152 |
+
# MULTI-LANGUAGES GIF GENERATOR AI
|
153 |
""")
|
154 |
with gr.Row():
|
155 |
prompt = gr.Textbox(
|
|
|
159 |
rtl=True,
|
160 |
max_lines=1
|
161 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
with gr.Row():
|
163 |
run_button = gr.Button("START",elem_classes="btn",scale=0)
|
164 |
with gr.Row():
|
165 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
166 |
+
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
167 |
with gr.Row():
|
168 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
169 |
+
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
170 |
|
171 |
+
def _ret(idx,p1):
|
172 |
+
print(f'Starting {idx}: {p1}')
|
173 |
+
v = infer(p1
|
174 |
+
|
175 |
+
)
|
176 |
print(f'Finished {idx}: {v}')
|
177 |
return v
|
178 |
+
def _rets(p1):
|
179 |
p1_en = translate(p1,"english")
|
|
|
180 |
ln = len(result)
|
181 |
idxs = list(range(ln))
|
182 |
p1s = [p1_en for _ in idxs]
|
183 |
+
return list(Pool(ln).imap( _ret, idxs, p1s ))
|
184 |
+
run_button.click(fn=_rets,inputs=[prompt],outputs=result)
|
|
|
185 |
|
186 |
demo.queue().launch()
|