Skip to content

Commit

Permalink
Merge pull request #1 from naseemap47/app
Browse files Browse the repository at this point in the history
App
  • Loading branch information
naseemap47 committed Jul 26, 2023
2 parents cca5b11 + 636a92e commit ce819a4
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Docker Image CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/streamlit-nafnet:latest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Model
*.pth
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
COPY . /home
RUN apt-get update && \
apt-get install -y \
python3 \
python3-pip \
ffmpeg \
libsm6 \
libxext6
WORKDIR /home
RUN pip install torch torchvision torchaudio
RUN pip install -r requirements.txt
RUN pip install --upgrade --no-cache-dir gdown
RUN python3 setup.py develop --no_cuda_ext
RUN pip install streamlit
RUN python3 -c "import gdown;gdown.download('https://drive.google.com/uc?id=14D4V4raNYIOhETfcuuLI3bGLB-OYIv6X', './experiments/pretrained_models/', quiet=False)"
CMD [ "streamlit", "run", "app.py" ]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# ImageRestoration-Streamlit
[<img src="https://img.shields.io/badge/Docker-Image-blue.svg?logo=docker">](<https://hub.docker.com/repository/docker/naseemap47/streamlit-nafnet>) <br>
Restore image using NAFNet model with streamlit dashboard

## Installtion
1. **Clone this Repo**
```
git clone https://github.com/naseemap47/ImageRestoration-Streamlit.git
cd ImageRestoration-Streamlit
```
2. **Install Libraries**
```
pip install -r requirements.txt
pip install --upgrade --no-cache-dir gdown
python3 setup.py develop --no_cuda_ext
pip install streamlit
```
## Download pretrained models
```
python3 -c "import gdown;gdown.download('https://drive.google.com/uc?id=14D4V4raNYIOhETfcuuLI3bGLB-OYIv6X', './experiments/pretrained_models/', quiet=False)"
```
## Run Dashboard
```
streamlit run app.py
```
53 changes: 53 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import streamlit as st
from basicsr.models import create_model
from basicsr.utils import img2tensor as _img2tensor, tensor2img
from basicsr.utils.options import parse
import numpy as np
import cv2


def img2tensor(img, bgr2rgb=False, float32=True):
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = img.astype(np.float32) / 255.
return _img2tensor(img, bgr2rgb=bgr2rgb, float32=float32)

def single_image_inference(model, img):
model.feed_data(data={'lq': img.unsqueeze(dim=0)})

if model.opt['val'].get('grids', False):
model.grids()

model.test()

if model.opt['val'].get('grids', False):
model.grids_inverse()

visuals = model.get_current_visuals()
sr_img = tensor2img([visuals['result']])
return sr_img


opt_path = 'options/test/REDS/NAFNet-width64.yml'
opt = parse(opt_path, is_train=False)
opt['dist'] = False
NAFNet = create_model(opt)

################## APP ##################
st.title('Unblur Image - NAFNet')

# Upload image
upload_img_file = st.file_uploader(
'Upload Image', type=['jpg', 'jpeg', 'png'])
FRAME_WINDOW = st.image([], channels='BGR')

if upload_img_file is not None:
file_bytes = np.asarray(
bytearray(upload_img_file.read()), dtype=np.uint8)
img_input = cv2.imdecode(file_bytes, 1)
FRAME_WINDOW.image(img_input, channels='BGR')

if st.button('Submit', use_container_width=True):
st.subheader('Result')
inp = img2tensor(img_input)
out_img = single_image_inference(NAFNet, inp)
st.image(out_img, channels='BGR')

0 comments on commit ce819a4

Please sign in to comment.