Spaces:
Runtime error
Runtime error
Commit
·
7656414
0
Parent(s):
Duplicate from cvsys/upscale
Browse filesCo-authored-by: mrfakename <mrfakename@users.noreply.huggingface.co>
- .gitattributes +35 -0
- README.md +14 -0
- app.py +127 -0
- no_vid.mp4 +0 -0
- requirements.txt +4 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: UPSCALE
|
3 |
+
emoji: 📷
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.35.2
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
duplicated_from: cvsys/upscale
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sldl.video import VideoSR
|
2 |
+
from sldl.image import ImageSR
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
import tempfile
|
6 |
+
import shutil
|
7 |
+
import torch
|
8 |
+
import ffmpeg
|
9 |
+
import time
|
10 |
+
from PIL import Image
|
11 |
+
|
12 |
+
cc = 2
|
13 |
+
if torch.backends.mps.is_available():
|
14 |
+
device = 'mps'
|
15 |
+
cc = 5
|
16 |
+
elif torch.cuda.is_available():
|
17 |
+
device = 'cuda'
|
18 |
+
cc = 10
|
19 |
+
else:
|
20 |
+
device = 'cpu'
|
21 |
+
|
22 |
+
vbsrgan = VideoSR('BSRGAN').to(device)
|
23 |
+
vresrgan = VideoSR('RealESRGAN').to(device)
|
24 |
+
ibsrgan = ImageSR('BSRGAN').to(device)
|
25 |
+
iresrgan = ImageSR('RealESRGAN').to(device)
|
26 |
+
|
27 |
+
def upscale_video(input_video, output_video, progress, mname):
|
28 |
+
modelname = mname.lower()
|
29 |
+
model = vbsrgan
|
30 |
+
if modelname == 'bsrgan (default)':
|
31 |
+
# do nothing
|
32 |
+
pass
|
33 |
+
elif modelname == 'real esrgan':
|
34 |
+
model = vresrgan
|
35 |
+
model(input_video, output_video, progress.tqdm)
|
36 |
+
|
37 |
+
def upscale_image(input_image, output_image, mname):
|
38 |
+
modelname = mname.lower()
|
39 |
+
model = ibsrgan
|
40 |
+
if modelname == 'bsrgan (default)':
|
41 |
+
# do nothing
|
42 |
+
pass
|
43 |
+
elif modelname == 'real esrgan':
|
44 |
+
model = iresrgan
|
45 |
+
shutil.copy(input_image, output_image)
|
46 |
+
model(output_image)
|
47 |
+
|
48 |
+
# Gradio interface
|
49 |
+
def video_upscaling_interface(input_text, model_name, progress=gr.Progress()):
|
50 |
+
if input_text:
|
51 |
+
temp_dir = tempfile.mkdtemp()
|
52 |
+
input_video_path = f"{temp_dir}/input_video"
|
53 |
+
output_video_path = f"{temp_dir}/output_video.mp4"
|
54 |
+
ffmpeg.input(input_text).output(input_video_path + '.mp4').run()
|
55 |
+
|
56 |
+
# Upscale the video
|
57 |
+
upscale_video(input_video_path + '.mp4', output_video_path, progress, model_name)
|
58 |
+
|
59 |
+
return [output_video_path, output_video_path]
|
60 |
+
else:
|
61 |
+
return ["no_vid.mp4", "no_vid.mp4"]
|
62 |
+
|
63 |
+
|
64 |
+
def image_upscaling_interface(input_text, model_name):
|
65 |
+
if input_text:
|
66 |
+
temp_dir = tempfile.mkdtemp()
|
67 |
+
input_image_path = f"{temp_dir}/input_image.jpg"
|
68 |
+
output_image_path = f"{temp_dir}/output_image.jpg"
|
69 |
+
input_text.save(input_image_path)
|
70 |
+
upscale_image(input_image_path, output_image_path, model_name)
|
71 |
+
return [output_image_path, output_image_path]
|
72 |
+
else:
|
73 |
+
return ["no_image.jpg", "no_image.jpg"]
|
74 |
+
|
75 |
+
|
76 |
+
css = "footer {display: none !important;} .gradio-container {min-height: 0px !important;}"
|
77 |
+
|
78 |
+
|
79 |
+
with gr.Blocks(css=css) as demo:
|
80 |
+
gr.Markdown('''
|
81 |
+
# Upscale
|
82 |
+
## A CVSYS Project
|
83 |
+
|
84 |
+
### NOTICE: This is running on a free Hugging Face Space, so it will be quite slow. Expect it to take _hours_ to upscale 5 minutes. Please be mindful and _DO NOT_ upscale videos longer than 15 seconds! Thank you!
|
85 |
+
|
86 |
+
[Check out Upscale on GitHub!](https://github.com/cv-sys/upscale)
|
87 |
+
|
88 |
+
## Want Faster Inference?
|
89 |
+
|
90 |
+
Duplicate this space for faster inference! We recommend using an A10G or A100.
|
91 |
+
|
92 |
+
<a href="https://huggingface.co/spaces/cvsys/upscale?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"></a>
|
93 |
+
|
94 |
+
Please note that after you upload an image, it may take several minutes before the progress bar appears. This is because we first convert your video to ensure the correct format.
|
95 |
+
''')
|
96 |
+
# with gr.Tab("Image"):
|
97 |
+
# with gr.Row():
|
98 |
+
# with gr.Column():
|
99 |
+
# iinp = gr.Image(label="Upload Image", interactive=True, type="pil")
|
100 |
+
# imod = gr.Dropdown(
|
101 |
+
# ["BSRGAN (Default)", "Real ESRGAN"],
|
102 |
+
# value="BSRGAN (Default)",
|
103 |
+
# interactive=True,
|
104 |
+
# label="Model"
|
105 |
+
# )
|
106 |
+
# with gr.Column():
|
107 |
+
# iout = gr.Image(label="View Image", interactive=False, type="filepath")
|
108 |
+
# ifile = gr.File(label="Download Image", interactive=False)
|
109 |
+
# ibtn = gr.Button(value="Upscale Image")
|
110 |
+
with gr.Tab("Video"):
|
111 |
+
with gr.Row():
|
112 |
+
with gr.Column():
|
113 |
+
vinp = gr.Video(label="Upload Video", interactive=True)
|
114 |
+
vmod = gr.Dropdown(
|
115 |
+
["BSRGAN (Default)", "Real ESRGAN"],
|
116 |
+
value="BSRGAN (Default)",
|
117 |
+
interactive=True,
|
118 |
+
label="Model"
|
119 |
+
)
|
120 |
+
with gr.Column():
|
121 |
+
vout = gr.Video(label="Watch Video", interactive=False)
|
122 |
+
vfile = gr.File(label="Download Video", interactive=False)
|
123 |
+
vbtn = gr.Button(value="Upscale Video")
|
124 |
+
# ibtn.click(image_upscaling_interface, [iinp, imod], outputs=[iout, ifile])
|
125 |
+
vbtn.click(video_upscaling_interface, [vinp, vmod], outputs=[vout, vfile])
|
126 |
+
demo.queue(concurrency_count=cc)
|
127 |
+
demo.launch()
|
no_vid.mp4
ADDED
Binary file (5.33 kB). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
git+https://github.com/fakerybakery/sldl-gr
|
3 |
+
ffmpeg-python
|
4 |
+
pillow
|