Coder Social home page Coder Social logo

kurp's Introduction

Komga and Kavita upscaling reverse proxy

Reverse proxy that intercepts image requests and applies upscaling. Other requests are transparently proxied without noticable delay

Building

required dependencies:

  • cmake
  • g++
  • vulkan loader library
  • ncnn
  • glslang
  1. run git submodule update --init --recursive to download subprojects required for build
  2. set GLSLANG_TARGET_DIR environment variable (ubuntu: /usr/lib/x86_64-linux-gnu/cmake/ arch linux: /usr/lib/cmake)
  3. run GLSLANG_TARGET_DIR=/usr/lib/cmake cargo build --release

Config

Config file must be named config.yml By default config file location is set to the current directory of execution. You can override config location with KURP_CONF_DIR environment variable. If no config file is found then default values will be used.

Default config

port: 3030 # listen port
upstream_url: "http://localhost:8080" # Komga or Kavita url
allow_config_updates: false # exposes config get and update enpoints that allow runtime config updates
upscale: true # enable upscaling
upscale_tag: # if present will only upscale if book or series contains specified tag. Komga only
size_threshold_enabled: true # enables content size check
size_threshold: 500 # in KB. will not upscale if image size is bigger than specified size
size_threshold_png: 1000 # in KB. will not upscale if image size is bigger than specified size. PNG only

# return format of the upscaled image. If the original image was png then converting for example to webp 
# will result in significantly smaller image size
# available options are "WebP", "Jpeg", "Png" and "Original"
return_format: WebP
upscaler: Waifu2x # upscaler to use (Waifu2x or Realcugan)

waifu2x:
  gpuid: 0 # gpu device to use (-1 = cpu). if you have single gpu then this should usually be 0
  scale: 2 # upscale ratio (1/2/4/8/16/32)
  noise: -1 # denoise level (-1/0/1/2/3)
  model: Cunet # waifu2x model (Cunet, Upconv7AnimeStyleArtRgb, Upconv7Photo)
  tile_size: 0 # tile size (>=32/0=auto)
  tta_mode: false # enable tta mode
  num_threads: 2 #  thread count used for upscaling
  models_path: "./models" # path to directory with models
  
realcugan:
  gpuid: 0 # gpu device to use (-1 = cpu). if you have single gpu then this should usually be 0
  scale: 2 # upscale ratio (1/2/3/4)
  noise: -1 # denoise level (-1/0/1/2/3)
  model: Se # realcugan model (Se, Pro, Nose)
  tile_size: 0 # tile size (>=32/0=auto)
  sync_gap: 3 # sync gap mode (0/1/2/3)
  tta_mode: false # enable tta mode
  num_threads: 2 #  thread count for upscaling
  models_path: "./models" # path to directory with models

Docker Compose

version: "3.7"
services:
  kurp:
    container_name: kurp
    image: sndxr/kurp:latest
    user: "1000:1000"
    # optional env configuration
    environment: 
      - RUST_LOG=info
      - KURP_UPSTREAM_URL=http://kavita:5000
      - KURP_UPSCALER=Waifu2x
      - KURP_WAIFU2X.GPUID=0
    volumes:
      - ./kurp:/config
    ports:
      - 3030:3030
    devices:
      - /dev/dri/renderD128:/dev/dri/renderD128
      - /dev/dri/card0:/dev/dri/card0
    restart: unless-stopped

kurp's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

bruhtek

kurp's Issues

[BUG] - Image Distortion

I've noticed I get image distortion occasionally (notice the signature blue bit it adds compared to the original), and I think it's Kurp thing, as I can access the image at the default komga url without any distortion. The majority of images are working, but usually about 1 page in any given chapter might do this. It does seem to do it consistently for the image even if I reload after clearing cache
image
image

port: 3030 # listen port
upstream_url: "http://localhost:8443"
upscale: true
size_threshold_enabled: true # enables content size check
size_threshold: 1000 # in KB. will not upscale if image size is bigger than specified size
size_threshold_png: 2000 # in KB. will not upscale if image size is bigger than specified size. PNG only

# return format of the upscaled image. If the original image was png then converting for example to webp
# will result in significantly smaller image size
# available options are "WebP", "Jpeg", "Png" and "Original"
return_format: WebP
upscaler: Realcugan # upscaler to use (Waifu2x or Realcugan)

waifu2x:
  # gpuid: 1 # gpu device to use (-1 = cpu). if you have single gpu then this should usually be 0
  scale: 2 # upscale ratio (1/2/4/8/16/32)
  noise: -1 # denoise level (-1/0/1/2/3)
  model: Cunet # waifu2x model (Cunet, Upconv7AnimeStyleArtRgb, Upconv7Photo)
  tile_size: 0 # tile size (>=32/0=auto)
  tta_mode: false # enable tta mode
  num_threads: 4 #  thread count used for upscaling
  models_path: "./models" # path to directory with models
realcugan:
  gpuid: 0 # gpu device to use (-1 = cpu). if you have single gpu then this should usually be 0
  scale: 2 # upscale ratio (1/2/3/4)
  noise: 0 # denoise level (-1/0/1/2/3)
  model: Se # realcugan model (Se, Pro, Nose)
  tile_size: 0 # tile size (>=32/0=auto)
  sync_gap: 3 # sync gap mode (0/1/2/3)
  tta_mode: false # enable tta mode
  num_threads: 8 #  thread count for upscaling
  models_path: "./models" # path to directory with models

Feature: Support AVIF

Now that the Komga Web UI supports AVIF, it would be great if we could get KURP to pass through the image. Currently it just sends back a broken image.

Reading Mode Issue

When using kurp and the reading mode is set to "Webtoon", the page jumps to that image every time an image is upscaled. This makes it impossible for readers using this reading mode to read due to the page scrolling around from image to image. Not sure if this can be prevented, if not, would it be possible to disable upscaling for this specific reading mode? To reproduce this issue, turn on webtoon reading mode and load up a book while kurp is running. Wait a few seconds or so for other pages to be upscaled, you will then see the page jumps from image to image.

how to set up models

I was hoping to try this project, but it seems I missed a step in the setup. I created a docker-compose.yml file, ran docker compose up and in the logs I see:

kurp  |  fopen /config/models/models-cunet/scale2.0x_model.param failed
kurp  |  fopen /config/models/models-cunet/scale2.0x_model.bin failed

I figured I need to download the models myself. Where should I download these models (waifu2x and realcugan) from? I tried cloning these repos:

and changing models_path for waifu2x and realcugan entries in config.yml to the models directory in the corresponding repos.

I am not sure if this is the right way as for waifu2x kurp tries to open models/models-cunet/scale2.0x_model.param and there is no models-cunet directory in the repo (there's only a cunet directory with incompatible files).

Upscaling for Kavita returns 200 but doesn't load the image.

[0 llvmpipe (LLVM 15.0.6, 128 bits)]  queueC=0[1]  queueG=0[1]  queueT=0[1]
[0 llvmpipe (LLVM 15.0.6, 128 bits)]  bugsbn1=0  bugbilz=0  bugcopc=0  bugihfa=0
[0 llvmpipe (LLVM 15.0.6, 128 bits)]  fp16-p/s/a=1/1/0  int8-p/s/a=1/1/1
[0 llvmpipe (LLVM 15.0.6, 128 bits)]  subgroup=4  basic=1  vote=1  ballot=1  shuffle=1
[2024-03-28T22:03:10Z INFO  kurp::handlers::upscale] GET /api/reader/image: upstream response: 200 OK
[2024-03-28T22:03:10Z INFO  kurp::handlers::upscale] GET /api/reader/image: upstream response: 200 OK
[2024-03-28T22:03:10Z INFO  kurp::handlers::upscale] GET /api/reader/image: upstream response: 200 OK
[2024-03-28T22:03:10Z INFO  kurp::handlers::upscale] GET /api/reader/image: upstream response: 200 OK
LLVM ERROR: Cannot select: 0x7f51842316c0: i16,ch = X86ISD::FILD<(load (s16) from %stack.8)> 0x7f51841e9180, FrameIndex:i64<8>
  0x7f51841e9048: i64 = FrameIndex<8>
In function: cs_co_variant
[2024-03-28T22:03:10Z INFO  kurp::handlers::upscale] GET /api/reader/image: upstream response: 200 OK
[0 llvmpipe (LLVM 15.0.6, 128 bits)]  queueC=0[1]  queueG=0[1]  queueT=0[1]
[0 llvmpipe (LLVM 15.0.6, 128 bits)]  bugsbn1=0  bugbilz=0  bugcopc=0  bugihfa=0
[0 llvmpipe (LLVM 15.0.6, 128 bits)]  fp16-p/s/a=1/1/0  int8-p/s/a=1/1/1
[0 llvmpipe (LLVM 15.0.6, 128 bits)]  subgroup=4  basic=1  vote=1  ballot=1  shuffle=1
[2024-03-28T22:03:14Z INFO  kurp::handlers::upscale] GET /api/reader/image: upstream response: 200 OK
[2024-03-28T22:03:14Z INFO  kurp::handlers::upscale] GET /api/reader/image: upstream response: 200 OK
LLVM ERROR: Cannot select: 0x7f6084230b80: i16,ch = X86ISD::FILD<(load (s16) from %stack.8)> 0x7f6084221950, FrameIndex:i64<8>
  0x7f6084221818: i64 = FrameIndex<8>
In function: cs_co_variant

Shows the response as okay but I suspect something with the image API has changed and it's causing images not to load at all.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.