Julssito Zaesar commited on
Commit
1b256e6
β€’
0 Parent(s):

Duplicate from AIFILMS/Pix2Pix-Video

Browse files

Co-authored-by: Cesar Romero <Zaesar@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ Ocean_Pexels_[[:space:]]8953474_512x512.mp4 filter=lfs diff=lfs merge=lfs -text
36
+ pexels-jill-burrow-7665249_512x512.mp4 filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Pix2Pix Video
3
+ emoji: 🎨🎞️
4
+ colorFrom: pink
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.18.0
8
+ app_file: app.py
9
+ pinned: true
10
+ duplicated_from: AIFILMS/Pix2Pix-Video
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import cv2
4
+ import numpy as np
5
+ from moviepy.editor import *
6
+ from share_btn import community_icon_html, loading_icon_html, share_js
7
+
8
+ from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler
9
+ import torch
10
+ from PIL import Image
11
+ import time
12
+ import psutil
13
+ import random
14
+
15
+ is_shared_ui = True if "AIFILMS/Pix2Pix-Video" in os.environ['SPACE_ID'] else False
16
+
17
+ pipe = DiffusionPipeline.from_pretrained("timbrooks/instruct-pix2pix", torch_dtype=torch.float16, safety_checker=None)
18
+ pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
19
+ if(not is_shared_ui):
20
+ pipe.enable_xformers_memory_efficient_attention()
21
+ pipe.unet.to(memory_format=torch.channels_last)
22
+
23
+ device = "GPU πŸ”₯" if torch.cuda.is_available() else "CPU πŸ₯Ά"
24
+
25
+ if torch.cuda.is_available():
26
+ pipe = pipe.to("cuda")
27
+
28
+ def pix2pix(
29
+ prompt,
30
+ text_guidance_scale,
31
+ image_guidance_scale,
32
+ image,
33
+ steps,
34
+ neg_prompt="",
35
+ width=512,
36
+ height=512,
37
+ seed=0,
38
+ ):
39
+ print(psutil.virtual_memory()) # print memory usage
40
+
41
+ if seed == 0:
42
+ seed = random.randint(0, 2147483647)
43
+
44
+ generator = torch.Generator("cuda").manual_seed(seed)
45
+
46
+ try:
47
+ image = Image.open(image)
48
+ ratio = min(height / image.height, width / image.width)
49
+ image = image.resize((int(image.width * ratio), int(image.height * ratio)), Image.LANCZOS)
50
+
51
+ result = pipe(
52
+ prompt,
53
+ negative_prompt=neg_prompt,
54
+ image=image,
55
+ num_inference_steps=int(steps),
56
+ image_guidance_scale=image_guidance_scale,
57
+ guidance_scale=text_guidance_scale,
58
+ generator=generator,
59
+ )
60
+
61
+ # return replace_nsfw_images(result)
62
+ return result.images, result.nsfw_content_detected, seed
63
+ except Exception as e:
64
+ return None, None, error_str(e)
65
+
66
+ def error_str(error, title="Error"):
67
+ return (
68
+ f"""#### {title}
69
+ {error}"""
70
+ if error
71
+ else ""
72
+ )
73
+
74
+ def get_frames(video_in):
75
+ frames = []
76
+ #resize the video
77
+ clip = VideoFileClip(video_in)
78
+
79
+ #check fps
80
+ if clip.fps > 30:
81
+ print("vide rate is over 30, resetting to 30")
82
+ clip_resized = clip.resize(height=512)
83
+ clip_resized.write_videofile("video_resized.mp4", fps=30)
84
+ else:
85
+ print("video rate is OK")
86
+ clip_resized = clip.resize(height=512)
87
+ clip_resized.write_videofile("video_resized.mp4", fps=clip.fps)
88
+
89
+ print("video resized to 512 height")
90
+
91
+ # Opens the Video file with CV2
92
+ cap= cv2.VideoCapture("video_resized.mp4")
93
+
94
+ fps = cap.get(cv2.CAP_PROP_FPS)
95
+ print("video fps: " + str(fps))
96
+ i=0
97
+ while(cap.isOpened()):
98
+ ret, frame = cap.read()
99
+ if ret == False:
100
+ break
101
+ cv2.imwrite('kang'+str(i)+'.jpg',frame)
102
+ frames.append('kang'+str(i)+'.jpg')
103
+ i+=1
104
+
105
+ cap.release()
106
+ cv2.destroyAllWindows()
107
+ print("broke the video into frames")
108
+
109
+ return frames, fps
110
+
111
+
112
+ def create_video(frames, fps):
113
+ print("building video result")
114
+ clip = ImageSequenceClip(frames, fps=fps)
115
+ clip.write_videofile("movie.mp4", fps=fps)
116
+
117
+ return 'movie.mp4'
118
+
119
+
120
+ def infer(prompt,video_in, seed_in, trim_value):
121
+ if(is_shared_ui):
122
+ raise gr.Error("This Space doesn't work on this shared UI.")
123
+ print(prompt)
124
+ break_vid = get_frames(video_in)
125
+
126
+ frames_list= break_vid[0]
127
+ fps = break_vid[1]
128
+ n_frame = int(trim_value*fps)
129
+
130
+ if n_frame >= len(frames_list):
131
+ print("video is shorter than the cut value")
132
+ n_frame = len(frames_list)
133
+
134
+ result_frames = []
135
+ print("set stop frames to: " + str(n_frame))
136
+
137
+ for i in frames_list[0:int(n_frame)]:
138
+ pix2pix_img = pix2pix(prompt,5.5,1.5,i,15,"",512,512,seed_in)
139
+ images = pix2pix_img[0]
140
+ rgb_im = images[0].convert("RGB")
141
+
142
+ # exporting the image
143
+ rgb_im.save(f"result_img-{i}.jpg")
144
+ result_frames.append(f"result_img-{i}.jpg")
145
+ print("frame " + i + "/" + str(n_frame) + ": done;")
146
+
147
+ final_vid = create_video(result_frames, fps)
148
+ print("finished !")
149
+
150
+ return final_vid, gr.Group.update(visible=True)
151
+
152
+ title = """
153
+ <div style="text-align: center; max-width: 700px; margin: 0 auto;">
154
+ <div
155
+ style="
156
+ display: inline-flex;
157
+ align-items: center;
158
+ gap: 0.8rem;
159
+ font-size: 1.75rem;
160
+ "
161
+ >
162
+ <h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
163
+ Pix2Pix Video
164
+ </h1>
165
+ </div>
166
+ <p style="margin-bottom: 10px; font-size: 94%">
167
+ Apply Instruct Pix2Pix Diffusion to a video
168
+ </p>
169
+ </div>
170
+ """
171
+
172
+ article = """
173
+
174
+ <div class="footer">
175
+ <p>
176
+ Examples by <a href="https://twitter.com/CitizenPlain" target="_blank">Nathan Shipley</a> β€’&nbsp;
177
+ Follow <a href="https://twitter.com/fffiloni" target="_blank">Sylvain Filoni</a> for future updates πŸ€—
178
+ </p>
179
+ </div>
180
+ <div id="may-like-container" style="display: flex;justify-content: center;flex-direction: column;align-items: center;margin-bottom: 30px;">
181
+ <p>You may also like: </p>
182
+ <div id="may-like-content" style="display:flex;flex-wrap: wrap;align-items:center;height:20px;">
183
+
184
+ <svg height="20" width="162" style="margin-left:4px;margin-bottom: 6px;">
185
+ <a href="https://huggingface.co/spaces/timbrooks/instruct-pix2pix" target="_blank">
186
+ <image href="https://img.shields.io/badge/πŸ€— Spaces-Instruct_Pix2Pix-blue" src="https://img.shields.io/badge/πŸ€— Spaces-Instruct_Pix2Pix-blue.png" height="20"/>
187
+ </a>
188
+ </svg>
189
+
190
+ </div>
191
+
192
+ </div>
193
+
194
+ """
195
+
196
+ with gr.Blocks(css='style.css') as demo:
197
+ if(is_shared_ui):
198
+ with gr.Box():
199
+ top_description = gr.HTML(f'''
200
+ <div class="gr-prose" style="max-width: 80%">
201
+ <h2 style="margin-top: 0">Attention - This Space doesn't work in this shared UI</h2>
202
+ <p>For it to work, you can access the <a href="https://huggingface.co/spaces/fffiloni/Pix2Pix-Video">original</a> or duplicate this Space and run it on your own profile using a GPU.&nbsp;&nbsp;<a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></p>
203
+ </div>
204
+ ''')
205
+ with gr.Column(elem_id="col-container"):
206
+ gr.HTML(title)
207
+ with gr.Row():
208
+ with gr.Column():
209
+ video_inp = gr.Video(label="Video source", source="upload", type="filepath", elem_id="input-vid")
210
+ prompt = gr.Textbox(label="Prompt", placeholder="enter prompt", show_label=False, elem_id="prompt-in")
211
+ with gr.Row():
212
+ seed_inp = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, value=123456)
213
+ trim_in = gr.Slider(label="Cut video at (s)", minimun=1, maximum=3, step=1, value=1)
214
+ with gr.Column():
215
+ video_out = gr.Video(label="Pix2pix video result", elem_id="video-output")
216
+ gr.HTML("""
217
+ <a style="display:inline-block" href="https://huggingface.co/spaces/fffiloni/Pix2Pix-Video?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a>
218
+ work with longer videos / skip the queue:
219
+ """, elem_id="duplicate-container")
220
+ submit_btn = gr.Button("Generate Pix2Pix video")
221
+
222
+ with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
223
+ community_icon = gr.HTML(community_icon_html)
224
+ loading_icon = gr.HTML(loading_icon_html)
225
+ share_button = gr.Button("Share to community", elem_id="share-btn")
226
+
227
+ inputs = [prompt,video_inp,seed_inp, trim_in]
228
+ outputs = [video_out, share_group]
229
+
230
+ ex = gr.Examples(
231
+ [
232
+ ["Make it a marble sculpture", "./examples/pexels-jill-burrow-7665249_512x512.mp4", 422112651, 4],
233
+ ["Make it molten lava", "./examples/Ocean_Pexels_ 8953474_512x512.mp4", 43571876, 4]
234
+ ],
235
+ inputs=inputs,
236
+ outputs=outputs,
237
+ fn=infer,
238
+ cache_examples=False,
239
+ )
240
+
241
+ gr.HTML(article)
242
+
243
+ submit_btn.click(infer, inputs, outputs)
244
+ share_button.click(None, [], [], _js=share_js)
245
+
246
+
247
+
248
+ demo.launch().queue(max_size=12)
examples/Ocean_Pexels_ 8953474_512x512.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6663980342c9e9a83f5e94299dbad77d76d59eb09134bc7c46f9a22fb436dcd2
3
+ size 3952041
examples/pexels-jill-burrow-7665249_512x512.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:afc3c03c6d8ccd67b0e6b0cadf0cfb14fc0785f72b26988be48141257043252f
3
+ size 3092936
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ opencv-python
2
+ ffmpeg-python
3
+ moviepy
4
+ --extra-index-url https://download.pytorch.org/whl/cu113
5
+ torch
6
+ torchvision==0.13.1+cu113
7
+ git+https://github.com/huggingface/diffusers.git
8
+ git+https://github.com/huggingface/transformers
9
+ scipy
10
+ ftfy
11
+ psutil
12
+ accelerate
13
+ safetensors
14
+ transformers
15
+ safetensors
16
+ --pre
17
+ xformers
share_btn.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ community_icon_html = """<svg id="share-btn-share-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32">
2
+ <path d="M20.6081 3C21.7684 3 22.8053 3.49196 23.5284 4.38415C23.9756 4.93678 24.4428 5.82749 24.4808 7.16133C24.9674 7.01707 25.4353 6.93643 25.8725 6.93643C26.9833 6.93643 27.9865 7.37587 28.696 8.17411C29.6075 9.19872 30.0124 10.4579 29.8361 11.7177C29.7523 12.3177 29.5581 12.8555 29.2678 13.3534C29.8798 13.8646 30.3306 14.5763 30.5485 15.4322C30.719 16.1032 30.8939 17.5006 29.9808 18.9403C30.0389 19.0342 30.0934 19.1319 30.1442 19.2318C30.6932 20.3074 30.7283 21.5229 30.2439 22.6548C29.5093 24.3704 27.6841 25.7219 24.1397 27.1727C21.9347 28.0753 19.9174 28.6523 19.8994 28.6575C16.9842 29.4379 14.3477 29.8345 12.0653 29.8345C7.87017 29.8345 4.8668 28.508 3.13831 25.8921C0.356375 21.6797 0.754104 17.8269 4.35369 14.1131C6.34591 12.058 7.67023 9.02782 7.94613 8.36275C8.50224 6.39343 9.97271 4.20438 12.4172 4.20438H12.4179C12.6236 4.20438 12.8314 4.2214 13.0364 4.25468C14.107 4.42854 15.0428 5.06476 15.7115 6.02205C16.4331 5.09583 17.134 4.359 17.7682 3.94323C18.7242 3.31737 19.6794 3 20.6081 3ZM20.6081 5.95917C20.2427 5.95917 19.7963 6.1197 19.3039 6.44225C17.7754 7.44319 14.8258 12.6772 13.7458 14.7131C13.3839 15.3952 12.7655 15.6837 12.2086 15.6837C11.1036 15.6837 10.2408 14.5497 12.1076 13.1085C14.9146 10.9402 13.9299 7.39584 12.5898 7.1776C12.5311 7.16799 12.4731 7.16355 12.4172 7.16355C11.1989 7.16355 10.6615 9.33114 10.6615 9.33114C10.6615 9.33114 9.0863 13.4148 6.38031 16.206C3.67434 18.998 3.5346 21.2388 5.50675 24.2246C6.85185 26.2606 9.42666 26.8753 12.0653 26.8753C14.8021 26.8753 17.6077 26.2139 19.1799 25.793C19.2574 25.7723 28.8193 22.984 27.6081 20.6107C27.4046 20.212 27.0693 20.0522 26.6471 20.0522C24.9416 20.0522 21.8393 22.6726 20.5057 22.6726C20.2076 22.6726 19.9976 22.5416 19.9116 22.222C19.3433 20.1173 28.552 19.2325 27.7758 16.1839C27.639 15.6445 27.2677 15.4256 26.746 15.4263C24.4923 15.4263 19.4358 19.5181 18.3759 19.5181C18.2949 19.5181 18.2368 19.4937 18.2053 19.4419C17.6743 18.557 17.9653 17.9394 21.7082 15.6009C25.4511 13.2617 28.0783 11.8545 26.5841 10.1752C26.4121 9.98141 26.1684 9.8956 25.8725 9.8956C23.6001 9.89634 18.2311 14.9403 18.2311 14.9403C18.2311 14.9403 16.7821 16.496 15.9057 16.496C15.7043 16.496 15.533 16.4139 15.4169 16.2112C14.7956 15.1296 21.1879 10.1286 21.5484 8.06535C21.7928 6.66715 21.3771 5.95917 20.6081 5.95917Z" fill="#FF9D00"></path>
3
+ <path d="M5.50686 24.2246C3.53472 21.2387 3.67446 18.9979 6.38043 16.206C9.08641 13.4147 10.6615 9.33111 10.6615 9.33111C10.6615 9.33111 11.2499 6.95933 12.59 7.17757C13.93 7.39581 14.9139 10.9401 12.1069 13.1084C9.29997 15.276 12.6659 16.7489 13.7459 14.713C14.8258 12.6772 17.7747 7.44316 19.304 6.44221C20.8326 5.44128 21.9089 6.00204 21.5484 8.06532C21.188 10.1286 14.795 15.1295 15.4171 16.2118C16.0391 17.2934 18.2312 14.9402 18.2312 14.9402C18.2312 14.9402 25.0907 8.49588 26.5842 10.1752C28.0776 11.8545 25.4512 13.2616 21.7082 15.6008C17.9646 17.9393 17.6744 18.557 18.2054 19.4418C18.7372 20.3266 26.9998 13.1351 27.7759 16.1838C28.5513 19.2324 19.3434 20.1173 19.9117 22.2219C20.48 24.3274 26.3979 18.2382 27.6082 20.6107C28.8193 22.9839 19.2574 25.7722 19.18 25.7929C16.0914 26.62 8.24723 28.3726 5.50686 24.2246Z" fill="#FFD21E"></path>
4
+ </svg>"""
5
+
6
+ loading_icon_html = """<svg id="share-btn-loading-icon" style="display:none;" class="animate-spin"
7
+ style="color: #ffffff;
8
+ "
9
+ xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" fill="none" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>"""
10
+
11
+ share_js = """async () => {
12
+ async function uploadFile(file){
13
+ const UPLOAD_URL = 'https://huggingface.co/uploads';
14
+ const response = await fetch(UPLOAD_URL, {
15
+ method: 'POST',
16
+ headers: {
17
+ 'Content-Type': file.type,
18
+ 'X-Requested-With': 'XMLHttpRequest',
19
+ },
20
+ body: file, /// <- File inherits from Blob
21
+ });
22
+ const url = await response.text();
23
+ return url;
24
+ }
25
+
26
+ async function getVideoBlobFile(videoEL){
27
+ const res = await fetch(videoEL.src);
28
+ const blob = await res.blob();
29
+ const videoId = Date.now() % 200;
30
+ const fileName = `vid-pix2pix-${{videoId}}.wav`;
31
+ const videoBlob = new File([blob], fileName, { type: 'video/mp4' });
32
+ console.log(videoBlob);
33
+ return videoBlob;
34
+ }
35
+
36
+ const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
37
+ const captionTxt = gradioEl.querySelector('#prompt-in textarea').value;
38
+ const inputVidEl = gradioEl.querySelector('#input-vid video');
39
+ const outputVideo = gradioEl.querySelector('#video-output video');
40
+
41
+
42
+ const shareBtnEl = gradioEl.querySelector('#share-btn');
43
+ const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
44
+ const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
45
+ if(!outputVideo){
46
+ return;
47
+ };
48
+ shareBtnEl.style.pointerEvents = 'none';
49
+ shareIconEl.style.display = 'none';
50
+ loadingIconEl.style.removeProperty('display');
51
+
52
+ const inputFile = await getVideoBlobFile(inputVidEl);
53
+ const urlInputVid = await uploadFile(inputFile);
54
+ const videoOutFile = await getVideoBlobFile(outputVideo);
55
+ const dataOutputVid = await uploadFile(videoOutFile);
56
+
57
+ const descriptionMd = `
58
+ #### Video input:
59
+ ${urlInputVid}
60
+
61
+ #### Pix2Pix result:
62
+ ${dataOutputVid}
63
+ `;
64
+ const params = new URLSearchParams({
65
+ title: captionTxt,
66
+ description: descriptionMd,
67
+ });
68
+ const paramsStr = params.toString();
69
+ window.open(`https://huggingface.co/spaces/fffiloni/Pix2Pix-Video/discussions/new?${paramsStr}`, '_blank');
70
+ shareBtnEl.style.removeProperty('pointer-events');
71
+ shareIconEl.style.removeProperty('display');
72
+ loadingIconEl.style.display = 'none';
73
+ }"""
style.css ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #col-container {max-width: 820px; margin-left: auto; margin-right: auto;}
2
+ #duplicate-container{
3
+ display: flex;
4
+ justify-content: space-between;
5
+ align-items: center;
6
+ line-height: 1em;
7
+ flex-direction: row-reverse;
8
+ font-size:1em;
9
+ }
10
+ a, a:hover, a:visited {
11
+ text-decoration-line: underline;
12
+ font-weight: 600;
13
+ color: #1f2937 !important;
14
+ }
15
+
16
+ .dark a, .dark a:hover, .dark a:visited {
17
+ color: #f3f4f6 !important;
18
+ }
19
+
20
+ .footer {
21
+ margin-bottom: 45px;
22
+ margin-top: 10px;
23
+ text-align: center;
24
+ border-bottom: 1px solid #e5e5e5;
25
+ }
26
+
27
+ .footer>p {
28
+ font-size: .8rem!important;
29
+ display: inline-block;
30
+ padding: 0 10px;
31
+ transform: translateY(26px);
32
+ background: white;
33
+ }
34
+ .dark .footer {
35
+ border-color: #303030;
36
+ }
37
+ .dark .footer>p {
38
+ background: #0b0f19;
39
+ }
40
+
41
+ div#may-like-container > p {
42
+ font-size: .8em;
43
+ margin-bottom: 4px;
44
+ }
45
+
46
+ .animate-spin {
47
+ animation: spin 1s linear infinite;
48
+ }
49
+
50
+ @keyframes spin {
51
+ from {
52
+ transform: rotate(0deg);
53
+ }
54
+ to {
55
+ transform: rotate(360deg);
56
+ }
57
+ }
58
+
59
+ #share-btn-container {
60
+ display: flex;
61
+ padding-left: 0.5rem !important;
62
+ padding-right: 0.5rem !important;
63
+ background-color: #000000;
64
+ justify-content: center;
65
+ align-items: center;
66
+ border-radius: 9999px !important;
67
+ max-width: 13rem;
68
+ }
69
+
70
+ #share-btn-container:hover {
71
+ background-color: #060606;
72
+ }
73
+
74
+ #share-btn {
75
+ all: initial;
76
+ color: #ffffff;
77
+ font-weight: 600;
78
+ cursor:pointer;
79
+ font-family: 'IBM Plex Sans', sans-serif;
80
+ margin-left: 0.5rem !important;
81
+ padding-top: 0.5rem !important;
82
+ padding-bottom: 0.5rem !important;
83
+ right:0;
84
+ }
85
+
86
+ #share-btn * {
87
+ all: unset;
88
+ }
89
+
90
+ #share-btn-container div:nth-child(-n+2){
91
+ width: auto !important;
92
+ min-height: 0px !important;
93
+ }
94
+
95
+ #share-btn-container .wrap {
96
+ display: none !important;
97
+ }
98
+
99
+ #share-btn-container.hidden {
100
+ display: none!important;
101
+ }