Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
AuraSR-v2
Commits
43f12e23
"web/vscode:/vscode.git/clone" did not exist on "bfb13f5eee48545f1c4b0b8a377de80be84bb100"
Commit
43f12e23
authored
Aug 02, 2024
by
chenpangpang
Browse files
feat: gradio页面优化:显示中文,直接显示生成图片;去除不必要的依赖
parent
cd084ed8
Pipeline
#1473
failed with stages
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
35 deletions
+24
-35
.gitignore
.gitignore
+1
-0
AuraSR-v2/app.py
AuraSR-v2/app.py
+22
-33
AuraSR-v2/requirements.txt
AuraSR-v2/requirements.txt
+1
-2
No files found.
.gitignore
View file @
43f12e23
.idea
.idea
chenyh
chenyh
.DS_Store
AuraSR-v2/app.py
View file @
43f12e23
import
spaces
import
gradio
as
gr
import
gradio
as
gr
from
gradio_imageslider
import
ImageSlider
from
PIL
import
Image
from
PIL
import
Image
import
numpy
as
np
from
aura_sr
import
AuraSR
from
aura_sr
import
AuraSR
import
torch
# Force CPU usage
# # Force CPU usage
torch
.
set_default_tensor_type
(
torch
.
FloatTensor
)
# torch.set_default_type(torch.FloatTensor)
# torch.set_default_device('cpu')
# Override torch.load to always use CPU
#
original_load
=
torch
.
load
# # Override torch.load to always use CPU
torch
.
load
=
lambda
*
args
,
**
kwargs
:
original_load
(
*
args
,
**
kwargs
,
map_location
=
torch
.
device
(
'cpu'
))
# original_load = torch.load
# torch.load = lambda *args, **kwargs: original_load(*args, **kwargs, map_location=torch.device('cpu'))
# Initialize the AuraSR model
# Initialize the AuraSR model
aura_sr
=
AuraSR
.
from_pretrained
(
"fal/AuraSR-v2"
)
aura_sr
=
AuraSR
.
from_pretrained
(
"fal/AuraSR-v2/model.safetensors"
)
# Restore original torch.load
#
# Restore original torch.load
torch
.
load
=
original_load
#
torch.load = original_load
def
process_image
(
input_image
):
def
process_image
(
input_image
):
if
input_image
is
None
:
if
input_image
is
None
:
...
@@ -29,38 +27,29 @@ def process_image(input_image):
...
@@ -29,38 +27,29 @@ def process_image(input_image):
# Upscale the image using AuraSR
# Upscale the image using AuraSR
upscaled_image
=
process_image_on_gpu
(
pil_image
)
upscaled_image
=
process_image_on_gpu
(
pil_image
)
# Convert result to numpy array if it's not already
return
upscaled_image
result_array
=
np
.
array
(
upscaled_image
)
return
[
input_image
,
result_array
]
@
spaces
.
GPU
def
process_image_on_gpu
(
pil_image
):
def
process_image_on_gpu
(
pil_image
):
return
aura_sr
.
upscale_4x
(
pil_image
)
return
aura_sr
.
upscale_4x
(
pil_image
)
title
=
"""<h1 align="center">AuraSR-v2 - An open reproduction of the GigaGAN Upscaler from fal.ai</h1>
<p><center>
title
=
"""<h1 align="center">AuraSR-v2:一款基于GAN图像修复工具,可从低分辨率图片生成高分辨率图片</h1>"""
<a href="https://huggingface.co/fal/AuraSR-v2" target="_blank">[AuraSR-v2]</a>
<a href="https://blog.fal.ai/introducing-aurasr-an-open-reproduction-of-the-gigagan-upscaler-2/" target="_blank">[Blog Post]</a>
<a href="https://huggingface.co/fal-ai/AuraSR" target="_blank">[v1 Model Page]</a>
</center></p>
"""
with
gr
.
Blocks
()
as
demo
:
with
gr
.
Blocks
()
as
demo
:
gr
.
HTML
(
title
)
gr
.
HTML
(
title
)
with
gr
.
Row
():
with
gr
.
Row
():
with
gr
.
Column
(
scale
=
1
):
with
gr
.
Column
(
scale
=
1
):
input_image
=
gr
.
Image
(
label
=
"
Input Image
"
,
type
=
"numpy"
)
input_image
=
gr
.
Image
(
label
=
"
输入图片
"
,
type
=
"numpy"
)
process_btn
=
gr
.
Button
(
"
Upscale Image
"
)
process_btn
=
gr
.
Button
(
"
生成
"
)
with
gr
.
Column
(
scale
=
1
):
with
gr
.
Column
(
scale
=
1
):
output_slid
er
=
Image
Slider
(
label
=
"
Before / After"
,
type
=
"numpy
"
)
gall
er
y
=
gr
.
Image
(
label
=
"
生成图片
"
)
process_btn
.
click
(
process_btn
.
click
(
fn
=
process_image
,
fn
=
process_image
,
inputs
=
[
input_image
],
inputs
=
[
input_image
],
outputs
=
output_slid
er
outputs
=
gall
er
y
)
)
# Add examples
# Add examples
...
@@ -70,9 +59,9 @@ with gr.Blocks() as demo:
...
@@ -70,9 +59,9 @@ with gr.Blocks() as demo:
"image3.png"
"image3.png"
],
],
inputs
=
input_image
,
inputs
=
input_image
,
outputs
=
output_slid
er
,
outputs
=
gall
er
y
,
fn
=
process_image
,
fn
=
process_image
,
cache_examples
=
True
cache_examples
=
True
)
)
demo
.
launch
(
debug
=
True
)
demo
.
launch
(
server_name
=
'0.0.0.0'
,
share
=
True
)
\ No newline at end of file
AuraSR-v2/requirements.txt
View file @
43f12e23
spaces
spaces
aura-sr
aura-sr
gradio-imageslider
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment