Skip to content

Commit

Permalink
new release
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgatis committed Jan 11, 2023
1 parent f78aad4 commit 94b3c95
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 93 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [danielgatis]
custom: ["https://www.buymeacoffee.com/danielgatis"]
23 changes: 23 additions & 0 deletions .github/workflows/close_inactive_issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Close inactive issues

on:
schedule:
- cron: "30 1 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish to Pypi

on:
push:
tags:
- "v*.*.*"

jobs:
push_to_pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9

- name: "Installs dependencies"
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools wheel twine
- name: "Builds and uploads to PyPI"
run: |
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
env:
TWINE_USERNAME: ${{ secrets.PIPY_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PIPY_PASSWORD }}
27 changes: 1 addition & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,7 @@ Scan from a remote image

Scan from a local file
```bash
docscan -o path/to/output.png path/to/input.png
```

Scan from all images in a folder
```bash
docscan -p path/to/inputs
```

### Usage as a server

Start the server
```bash
docscan-server
```

Open your browser to
```
http://localhost:5000?url=http://image.png
```

Also you can send the file as a FormData (multipart/form-data):
```
<form action="http://localhost:5000" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submi"t value="upload"/>
</form>
docscan path/to/output.png path/to/input.png
```

### Usage as a library
Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rembg==1.0.16
opencv-python==4.4.0.42
imutils==0.5.3
numpy==1.19.1
flask==1.1.2
waitress==1.4.4
click
flask
imutils
numpy
opencv-python
rembg
waitress
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="docscan",
version="1.0.4",
version="1.0.5",
description="This is a document scanner",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
65 changes: 15 additions & 50 deletions src/docscan/cmd/cli.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,25 @@
import argparse
import glob
import imghdr
import os
import sys

from ..doc import scan


def main():
ap = argparse.ArgumentParser()

ap.add_argument(
"-p", "--path", nargs="+", help="Path of a file or a folder of files.",
)

ap.add_argument(
"-o",
"--output",
nargs="?",
default="-",
type=argparse.FileType("wb"),
help="Path to the output png image.",
)

ap.add_argument(
"input",
nargs="?",
default="-",
type=argparse.FileType("rb"),
help="Path to the input image.",
)
import click
import rembg

args = ap.parse_args()

r = lambda i: i.buffer.read() if hasattr(i, "buffer") else i.read()
w = lambda o, data: o.buffer.write(data) if hasattr(o, "buffer") else o.write(data)

if args.path:
full_paths = [os.path.abspath(path) for path in args.path]
files = set()

for path in full_paths:
if os.path.isfile(path):
files.add(path)
else:
full_paths += glob.glob(path + "/*")

for fi in files:
if imghdr.what(fi) is None:
continue
from ..doc import scan

with open(fi, "rb") as input:
with open(os.path.splitext(fi)[0] + ".out.png", "wb") as output:
w(output, scan(r(input)))

else:
w(args.output, scan(r(args.input)))
@click.command()
@click.argument(
"input", default=(None if sys.stdin.isatty() else "-"), type=click.File("rb")
)
@click.argument(
"output",
default=(None if sys.stdin.isatty() else "-"),
type=click.File("wb", lazy=True),
)
def main(input, output):
output.write(rembg.remove(input.read()))


if __name__ == "__main__":
Expand Down
28 changes: 18 additions & 10 deletions src/docscan/cmd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
@app.route("/", methods=["GET", "POST"])
def index():
file_content = ''
file_content = ""

if request.method == 'POST':
if 'file' not in request.files:
if request.method == "POST":
if "file" not in request.files:
return {"error": "missing post form param 'file'"}, 400

file_content = request.files['file'].read();
file_content = request.files["file"].read()

if request.method == 'GET':
if request.method == "GET":
url = request.args.get("url", type=str)
if url is None:
return {"error": "missing query param 'url'"}, 400

file_content = urlopen(unquote_plus(url)).read();
file_content = urlopen(unquote_plus(url)).read()

if file_content == '':
if file_content == "":
return {"error": "File content is empty"}, 400

try:
Expand All @@ -45,11 +45,19 @@ def main():
ap = argparse.ArgumentParser()

ap.add_argument(
"-a", "--addr", default="0.0.0.0", type=str, help="The IP address to bind to.",
"-a",
"--addr",
default="0.0.0.0",
type=str,
help="The IP address to bind to.",
)

ap.add_argument(
"-p", "--port", default=5000, type=int, help="The port to bind to.",
"-p",
"--port",
default=5000,
type=int,
help="The port to bind to.",
)

args = ap.parse_args()
Expand Down

0 comments on commit 94b3c95

Please sign in to comment.