-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from naseemap47/app
App
- Loading branch information
Showing
5 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |