Spaces:
Running
Running
Merge branch 'master'
Browse files- .dockerignore +34 -0
- .gitignore +10 -0
- .python-version +1 -0
- Dockerfile +45 -0
- README.md +5 -6
- main.py +49 -0
- pyproject.toml +15 -0
- uv.lock +0 -0
.dockerignore
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Include any files or directories that you don't want to be copied to your
|
| 2 |
+
# container here (e.g., local build artifacts, temporary files, etc.).
|
| 3 |
+
#
|
| 4 |
+
# For more help, visit the .dockerignore file reference guide at
|
| 5 |
+
# https://docs.docker.com/go/build-context-dockerignore/
|
| 6 |
+
|
| 7 |
+
**/.DS_Store
|
| 8 |
+
**/__pycache__
|
| 9 |
+
**/.venv
|
| 10 |
+
**/.classpath
|
| 11 |
+
**/.dockerignore
|
| 12 |
+
**/.env
|
| 13 |
+
**/.git
|
| 14 |
+
**/.gitignore
|
| 15 |
+
**/.project
|
| 16 |
+
**/.settings
|
| 17 |
+
**/.toolstarget
|
| 18 |
+
**/.vs
|
| 19 |
+
**/.vscode
|
| 20 |
+
**/*.*proj.user
|
| 21 |
+
**/*.dbmdl
|
| 22 |
+
**/*.jfm
|
| 23 |
+
**/bin
|
| 24 |
+
**/charts
|
| 25 |
+
**/docker-compose*
|
| 26 |
+
**/compose.y*ml
|
| 27 |
+
**/Dockerfile*
|
| 28 |
+
**/node_modules
|
| 29 |
+
**/npm-debug.log
|
| 30 |
+
**/obj
|
| 31 |
+
**/secrets.dev.yaml
|
| 32 |
+
**/values.dev.yaml
|
| 33 |
+
LICENSE
|
| 34 |
+
README.md
|
.gitignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python-generated files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[oc]
|
| 4 |
+
build/
|
| 5 |
+
dist/
|
| 6 |
+
wheels/
|
| 7 |
+
*.egg-info
|
| 8 |
+
|
| 9 |
+
# Virtual environments
|
| 10 |
+
.venv
|
.python-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
3.11
|
Dockerfile
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# syntax=docker/dockerfile:1
|
| 2 |
+
|
| 3 |
+
ARG PYTHON_VERSION=3.11
|
| 4 |
+
FROM python:${PYTHON_VERSION}-slim as base
|
| 5 |
+
|
| 6 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 7 |
+
ENV PYTHONUNBUFFERED=1
|
| 8 |
+
|
| 9 |
+
# Install uv
|
| 10 |
+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
| 11 |
+
|
| 12 |
+
WORKDIR /app
|
| 13 |
+
|
| 14 |
+
# Create a proper non-root user WITH home
|
| 15 |
+
ARG UID=10001
|
| 16 |
+
RUN adduser \
|
| 17 |
+
--disabled-password \
|
| 18 |
+
--gecos "" \
|
| 19 |
+
--uid "${UID}" \
|
| 20 |
+
appuser
|
| 21 |
+
|
| 22 |
+
# Set correct HOME and cache
|
| 23 |
+
ENV HOME=/home/appuser
|
| 24 |
+
ENV UV_CACHE_DIR=/home/appuser/.cache/uv
|
| 25 |
+
|
| 26 |
+
# Copy dependency files
|
| 27 |
+
COPY pyproject.toml uv.lock ./
|
| 28 |
+
|
| 29 |
+
# Install dependencies
|
| 30 |
+
RUN --mount=type=cache,target=/home/appuser/.cache/uv \
|
| 31 |
+
uv sync --frozen --no-install-project
|
| 32 |
+
|
| 33 |
+
# Copy source
|
| 34 |
+
COPY . .
|
| 35 |
+
|
| 36 |
+
# Install project
|
| 37 |
+
RUN --mount=type=cache,target=/home/appuser/.cache/uv \
|
| 38 |
+
uv sync --frozen
|
| 39 |
+
|
| 40 |
+
# Switch user
|
| 41 |
+
USER appuser
|
| 42 |
+
|
| 43 |
+
EXPOSE 7860
|
| 44 |
+
|
| 45 |
+
CMD ["uv", "run", "python", "main.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
---
|
| 2 |
-
title: Image Upscaler
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
-
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AI Image Upscaler
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
---
|
|
|
|
|
|
main.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from realesrgan import RealESRGANer
|
| 5 |
+
from basicsr.archs.rrdbnet_arch import RRDBNet
|
| 6 |
+
|
| 7 |
+
# Load model once at startup (not on every call)
|
| 8 |
+
def load_model(scale=4):
|
| 9 |
+
model = RRDBNet(
|
| 10 |
+
num_in_ch=3, num_out_ch=3,
|
| 11 |
+
num_feat=64, num_block=23, num_grow_ch=32, scale=scale
|
| 12 |
+
)
|
| 13 |
+
upsampler = RealESRGANer(
|
| 14 |
+
scale=scale,
|
| 15 |
+
model_path=f"https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x{scale}plus.pth",
|
| 16 |
+
model=model,
|
| 17 |
+
half=False # set True if GPU available
|
| 18 |
+
)
|
| 19 |
+
return upsampler
|
| 20 |
+
|
| 21 |
+
upsampler_cache = {}
|
| 22 |
+
|
| 23 |
+
def upscale(image: Image.Image, scale: int):
|
| 24 |
+
if scale not in upsampler_cache:
|
| 25 |
+
upsampler_cache[scale] = load_model(scale)
|
| 26 |
+
|
| 27 |
+
upsampler = upsampler_cache[scale]
|
| 28 |
+
img_array = np.array(image)
|
| 29 |
+
output, _ = upsampler.enhance(img_array, outscale=scale)
|
| 30 |
+
return Image.fromarray(output)
|
| 31 |
+
|
| 32 |
+
# Gradio UI
|
| 33 |
+
with gr.Blocks(title="AI Image Upscaler") as demo:
|
| 34 |
+
gr.Markdown("## π AI Image Upscaler\nPowered by Real-ESRGAN")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
with gr.Column():
|
| 38 |
+
input_img = gr.Image(type="pil", label="Input Image")
|
| 39 |
+
scale_choice = gr.Radio(
|
| 40 |
+
choices=[2, 4, 8], value=4, label="Upscale Factor"
|
| 41 |
+
)
|
| 42 |
+
btn = gr.Button("Upscale", variant="primary")
|
| 43 |
+
|
| 44 |
+
with gr.Column():
|
| 45 |
+
output_img = gr.Image(type="pil", label="Upscaled Output")
|
| 46 |
+
|
| 47 |
+
btn.click(fn=upscale, inputs=[input_img, scale_choice], outputs=output_img)
|
| 48 |
+
|
| 49 |
+
demo.launch()
|
pyproject.toml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "image-upscaler"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Add your description here"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.11"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"basicsr>=1.4.2",
|
| 9 |
+
"gradio>=6.11.0",
|
| 10 |
+
"numpy<2",
|
| 11 |
+
"pillow>=12.2.0",
|
| 12 |
+
"realesrgan>=0.3.0",
|
| 13 |
+
"torch==2.1.2",
|
| 14 |
+
"torchvision==0.16.2",
|
| 15 |
+
]
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|