Commit cd084ed8 authored by chenpangpang's avatar chenpangpang
Browse files

feat: 初识提交

parent 86a26d1e
Pipeline #1472 canceled with stages
.idea
chenyh
---
title: AuraSR-v2
emoji: 😻
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 4.37.1
app_file: app.py
pinned: false
license: apache-2.0
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
import spaces
import gradio as gr
from gradio_imageslider import ImageSlider
from PIL import Image
import numpy as np
from aura_sr import AuraSR
import torch
# Force CPU usage
torch.set_default_tensor_type(torch.FloatTensor)
# Override torch.load to always use CPU
original_load = torch.load
torch.load = lambda *args, **kwargs: original_load(*args, **kwargs, map_location=torch.device('cpu'))
# Initialize the AuraSR model
aura_sr = AuraSR.from_pretrained("fal/AuraSR-v2")
# Restore original torch.load
torch.load = original_load
def process_image(input_image):
if input_image is None:
raise gr.Error("Please provide an image to upscale.")
# Convert to PIL Image for resizing
pil_image = Image.fromarray(input_image)
# Upscale the image using AuraSR
upscaled_image = process_image_on_gpu(pil_image)
# Convert result to numpy array if it's not already
result_array = np.array(upscaled_image)
return [input_image, result_array]
@spaces.GPU
def process_image_on_gpu(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>
<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:
gr.HTML(title)
with gr.Row():
with gr.Column(scale=1):
input_image = gr.Image(label="Input Image", type="numpy")
process_btn = gr.Button("Upscale Image")
with gr.Column(scale=1):
output_slider = ImageSlider(label="Before / After", type="numpy")
process_btn.click(
fn=process_image,
inputs=[input_image],
outputs=output_slider
)
# Add examples
gr.Examples(
examples=[
"image1.png",
"image3.png"
],
inputs=input_image,
outputs=output_slider,
fn=process_image,
cache_examples=True
)
demo.launch(debug=True)
\ No newline at end of file
spaces
aura-sr
gradio-imageslider
\ No newline at end of file
FROM image.sourcefind.cn:5000/gpu/admin/base/jupyterlab-pytorch:2.2.0-python3.10-cuda12.1-ubuntu22.04 as base
ARG IMAGE=aurasr-v2
ARG IMAGE_UPPER=AuraSR-v2
ARG BRANCH=gpu
RUN cd /root && git clone -b $BRANCH http://developer.hpccube.com/codes/chenpangpang/$IMAGE.git
WORKDIR /root/$IMAGE/$IMAGE_UPPER
RUN pip install -r requirements.txt
#########
# Prod #
#########
FROM image.sourcefind.cn:5000/gpu/admin/base/jupyterlab-pytorch:2.2.0-python3.10-cuda12.1-ubuntu22.04
ARG IMAGE=aurasr-v2
ARG IMAGE_UPPER=AuraSR-v2
COPY chenyh/$IMAGE/frpc_linux_amd64_v0.2 /opt/conda/lib/python3.10/site-packages/gradio/
RUN chmod +x /opt/conda/lib/python3.10/site-packages/gradio/frpc_linux_amd64_v0.2
COPY chenyh/$IMAGE/fal/$IMAGE_UPPER /root/$IMAGE_UPPER/fal/$IMAGE_UPPER
COPY --from=base /opt/conda/lib/python3.10/site-packages /opt/conda/lib/python3.10/site-packages
COPY --from=base /root/$IMAGE/$IMAGE_UPPER /root/$IMAGE_UPPER
COPY --from=base /root/$IMAGE/启动器.ipynb /root/$IMAGE/start.sh /root/
# pip install huggingface-cli
import os
import requests
import json
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
model_list = [
"fal/AuraSR-v2"
]
for model_path in model_list:
os.system(f"huggingface-cli download --resume-download {model_path} --local-dir ./{model_path} --local-dir-use-symlinks False")
\ No newline at end of file
#!/bin/bash
cd /root/AuraSR-v2
python app.py
{
"cells": [
{
"cell_type": "markdown",
"id": "e5c5a211-2ccd-4341-af10-ac546484b91f",
"metadata": {
"tags": []
},
"source": [
"## 说明\n",
"- 启动需要加载模型,需要2分钟左右的时间\n",
"- 启动和重启 Notebook 点上方工具栏中的「重启并运行所有单元格」。出现如下内容就算成功了:\n",
" - `Running on local URL: http://0.0.0.0:7860`\n",
" - `Running on public URL: https://xxxxxxxxxxxxxxx.gradio.live`\n",
"- 通过以下方式开启页面:\n",
" - 控制台打开「自定义服务」了,访问自定义服务端口号设置为7860\n",
" - 直接打开显示的公开链接`public URL`\n",
"\n",
"## 功能介绍\n",
"- 原项目地址:https://huggingface.co/spaces/gokaygokay/AuraSR-v2\n",
"- AuraSR-v2:一款基于GAN图像修复工具,可从低分辨率图片生成高分辨率图片"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53a96614-e2d2-4710-a82b-0d5ca9cb9872",
"metadata": {
"tags": [],
"is_executing": true
},
"outputs": [],
"source": [
"# 启动\n",
"!sh start.sh"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e81ae9d-3a34-43a0-943a-ff5e9d6ce961",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment