spectraGAN / README.md
ParamAhuja
initial
3262d11

A newer version of the Gradio SDK is available: 6.10.0

Upgrade
metadata
title: SpectraGAN
emoji: πŸ–ΌοΈ
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 5.31.0
app_file: app.py
pinned: false
license: apache-2.0

πŸ–ΌοΈ SpectraGAN β€” Multi-Model Upscaler Comparison

A Gradio web app that lets you upscale an image with multiple SR models simultaneously and compare results side by side.

Supported models:

Model Architecture Scale
Real-ESRGAN Γ—2 GAN (residual-in-residual dense block) Γ—2
Real-ESRGAN Γ—4 GAN (residual-in-residual dense block) Γ—4
SRCNN Γ—4 Shallow 3-layer CNN Γ—4
HResNet Γ—4 Deep residual network (EDSR-style) Γ—4
SR3 (stub) Diffusion model Γ—4 β€” see note below

πŸ“‘ Table of Contents

  1. Features
  2. Project Structure
  3. Prerequisites
  4. Installation
  5. Adding Your ONNX Models
  6. Running Locally
  7. SR3 Integration Guide
  8. Contributing
  9. License

✨ Features

  • Side-by-side comparison β€” run up to 4 models at once, results displayed in a 4-panel grid.
  • Selective execution β€” toggle any model on/off before running; unchecked models are skipped.
  • Γ—8 post-resize β€” optionally apply a bicubic Γ—2 pass on top of any Γ—4 result.
  • Tile-based inference β€” large images are split into tiles matching each model's fixed input size, then stitched back together seamlessly.
  • Per-result download β€” each panel has its own PNG download button.
  • Graceful degradation β€” if a model file is missing (e.g. Drive ID not yet set), that panel is skipped without crashing the others.

πŸ“ Project Structure

spectragan/
β”œβ”€β”€ model/
β”‚   β”œβ”€β”€ Real-ESRGAN_x2plus.onnx   # auto-downloaded
β”‚   β”œβ”€β”€ Real-ESRGAN-x4plus.onnx   # auto-downloaded
β”‚   β”œβ”€β”€ SRCNN_x4.onnx              # you provide β€” see below
β”‚   └── HResNet_x4.onnx            # you provide β€” see below
β”œβ”€β”€ app.py
β”œβ”€β”€ requirements.txt
└── README.md

βš™οΈ Prerequisites

  • Python 3.10+
  • git
  • A terminal / command prompt

πŸ”§ Installation

git clone https://github.com/ParamAhuja/SpectraGAN.git
cd SpectraGAN
python -m venv .venv
source .venv/bin/activate      # Linux/macOS
# .venv\Scripts\activate       # Windows
pip install -r requirements.txt

πŸ—‚οΈ Adding Your ONNX Models

The Real-ESRGAN weights are downloaded automatically from Google Drive on first run.

For SRCNN and HResNet you need to:

  1. Export your trained PyTorch model to ONNX:
import torch

# SRCNN example
from srcnn import SRCNN
model = SRCNN()
model.load_state_dict(torch.load("srcnn.pth"))
model.eval()

dummy = torch.randn(1, 3, 128, 128)
torch.onnx.export(
    model, dummy, "SRCNN_x4.onnx",
    input_names=["input"], output_names=["output"],
    dynamic_axes={"input": {2: "H", 3: "W"}, "output": {2: "H", 3: "W"}}
)
  1. Upload the .onnx file to Google Drive and set "Anyone with the link can view".

  2. Copy the file ID from the share URL and update DRIVE_IDS in app.py:

DRIVE_IDS = {
    ...
    "srcnn_x4":   "YOUR_SRCNN_DRIVE_FILE_ID_HERE",
    "hresnet_x4": "YOUR_HRESNET_DRIVE_FILE_ID_HERE",
}

πŸš€ Running Locally

python app.py

Open http://127.0.0.1:7860 in your browser.


πŸŒ€ SR3 Integration Guide

SR3 (Super-Resolution via Repeated Refinement) is a diffusion model β€” it cannot be exported to a static ONNX graph because its inference involves a variable-length denoising loop.

To add SR3:

  1. Clone the reference implementation:

    git clone https://github.com/Janspiry/Image-Super-Resolution-via-Iterative-Refinement
    
  2. Place your trained checkpoint at model/sr3_x4.pth.

  3. Add torch and torchvision to requirements.txt.

  4. Write a wrapper in app.py:

    def run_sr3(input_img: Image.Image) -> Image.Image:
        # load config + model, run the denoising loop, return result
        ...
    
  5. Add "sr3_x4" to the PANEL_KEYS list and wire run_sr3 into compare_models.


🀝 Contributing

Pull requests welcome. Please open an issue first to discuss significant changes.


πŸ“„ License

Apache 2.0 β€” see LICENSE.


πŸ‘€ Author & Credits

  • Real-ESRGAN by xinntao
  • SRCNN by Dong et al. (2014)
  • HResNet / EDSR by Lim et al. (2017)
  • SR3 by Ho et al. (2022) β€” paper