Spaces:
Running
A newer version of the Gradio SDK is available: 6.10.0
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
- Features
- Project Structure
- Prerequisites
- Installation
- Adding Your ONNX Models
- Running Locally
- SR3 Integration Guide
- Contributing
- 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:
- 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"}}
)
Upload the
.onnxfile to Google Drive and set "Anyone with the link can view".Copy the file ID from the share URL and update
DRIVE_IDSinapp.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:
Clone the reference implementation:
git clone https://github.com/Janspiry/Image-Super-Resolution-via-Iterative-RefinementPlace your trained checkpoint at
model/sr3_x4.pth.Add
torchandtorchvisiontorequirements.txt.Write a wrapper in
app.py:def run_sr3(input_img: Image.Image) -> Image.Image: # load config + model, run the denoising loop, return result ...Add
"sr3_x4"to thePANEL_KEYSlist and wirerun_sr3intocompare_models.
π€ Contributing
Pull requests welcome. Please open an issue first to discuss significant changes.
π License
Apache 2.0 β see LICENSE.