init
This commit is contained in:
BIN
21/12/02/ja.jpeg
Normal file
BIN
21/12/02/ja.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 306 KiB |
BIN
db.sqlite3
Normal file
BIN
db.sqlite3
Normal file
Binary file not shown.
22
manage.py
Executable file
22
manage.py
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""Django's command-line utility for administrative tasks."""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Run administrative tasks."""
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ocr.settings')
|
||||||
|
try:
|
||||||
|
from django.core.management import execute_from_command_line
|
||||||
|
except ImportError as exc:
|
||||||
|
raise ImportError(
|
||||||
|
"Couldn't import Django. Are you sure it's installed and "
|
||||||
|
"available on your PYTHONPATH environment variable? Did you "
|
||||||
|
"forget to activate a virtual environment?"
|
||||||
|
) from exc
|
||||||
|
execute_from_command_line(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
0
ocr/__init__.py
Normal file
0
ocr/__init__.py
Normal file
BIN
ocr/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
ocr/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
ocr/__pycache__/settings.cpython-39.pyc
Normal file
BIN
ocr/__pycache__/settings.cpython-39.pyc
Normal file
Binary file not shown.
BIN
ocr/__pycache__/urls.cpython-39.pyc
Normal file
BIN
ocr/__pycache__/urls.cpython-39.pyc
Normal file
Binary file not shown.
BIN
ocr/__pycache__/wsgi.cpython-39.pyc
Normal file
BIN
ocr/__pycache__/wsgi.cpython-39.pyc
Normal file
Binary file not shown.
16
ocr/asgi.py
Normal file
16
ocr/asgi.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
ASGI config for ocr project.
|
||||||
|
|
||||||
|
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ocr.settings')
|
||||||
|
|
||||||
|
application = get_asgi_application()
|
||||||
127
ocr/settings.py
Normal file
127
ocr/settings.py
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
"""
|
||||||
|
Django settings for ocr project.
|
||||||
|
|
||||||
|
Generated by 'django-admin startproject' using Django 3.2.9.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.2/topics/settings/
|
||||||
|
|
||||||
|
For the full list of settings and their values, see
|
||||||
|
https://docs.djangoproject.com/en/3.2/ref/settings/
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
||||||
|
# Quick-start development settings - unsuitable for production
|
||||||
|
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
||||||
|
|
||||||
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
|
SECRET_KEY = 'django-insecure-#-a9k=#&y3e&a&@%rn7mhl@fk3smxceqh^@1)#9t@c-qzx&k^b'
|
||||||
|
|
||||||
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
|
# Application definition
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
'django.contrib.admin',
|
||||||
|
'django.contrib.auth',
|
||||||
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.sessions',
|
||||||
|
'django.contrib.messages',
|
||||||
|
'django.contrib.staticfiles',
|
||||||
|
'rest_framework',
|
||||||
|
'sumasen_easyocr',
|
||||||
|
]
|
||||||
|
|
||||||
|
MIDDLEWARE = [
|
||||||
|
'django.middleware.security.SecurityMiddleware',
|
||||||
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
'django.middleware.common.CommonMiddleware',
|
||||||
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
]
|
||||||
|
|
||||||
|
ROOT_URLCONF = 'ocr.urls'
|
||||||
|
|
||||||
|
TEMPLATES = [
|
||||||
|
{
|
||||||
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
'DIRS': [],
|
||||||
|
'APP_DIRS': True,
|
||||||
|
'OPTIONS': {
|
||||||
|
'context_processors': [
|
||||||
|
'django.template.context_processors.debug',
|
||||||
|
'django.template.context_processors.request',
|
||||||
|
'django.contrib.auth.context_processors.auth',
|
||||||
|
'django.contrib.messages.context_processors.messages',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
WSGI_APPLICATION = 'ocr.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
|
# Database
|
||||||
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': BASE_DIR / 'db.sqlite3',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Password validation
|
||||||
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Internationalization
|
||||||
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||||
|
|
||||||
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
|
USE_I18N = True
|
||||||
|
|
||||||
|
USE_L10N = True
|
||||||
|
|
||||||
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
|
# Static files (CSS, JavaScript, Images)
|
||||||
|
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
||||||
|
|
||||||
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
# Default primary key field type
|
||||||
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
22
ocr/urls.py
Normal file
22
ocr/urls.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"""ocr URL Configuration
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path, include
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('admin/', admin.site.urls),
|
||||||
|
path('api/v1/', include('sumasen_easyocr.urls'), name='ocr')
|
||||||
|
]
|
||||||
16
ocr/wsgi.py
Normal file
16
ocr/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
WSGI config for ocr project.
|
||||||
|
|
||||||
|
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ocr.settings')
|
||||||
|
|
||||||
|
application = get_wsgi_application()
|
||||||
29
requirements.txt
Normal file
29
requirements.txt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
asgiref==3.4.1
|
||||||
|
cycler==0.11.0
|
||||||
|
Django==3.2.9
|
||||||
|
easyocr==1.4.1
|
||||||
|
fonttools==4.28.2
|
||||||
|
imageio==2.9.0
|
||||||
|
kiwisolver==1.3.2
|
||||||
|
matplotlib==3.5.0
|
||||||
|
networkx==2.6.3
|
||||||
|
numpy==1.21.4
|
||||||
|
opencv-python-headless==4.5.4.60
|
||||||
|
packaging==21.3
|
||||||
|
Pillow==8.2.0
|
||||||
|
pyparsing==3.0.6
|
||||||
|
python-bidi==0.4.2
|
||||||
|
python-dateutil==2.8.2
|
||||||
|
pytz==2021.3
|
||||||
|
PyWavelets==1.2.0
|
||||||
|
PyYAML==6.0
|
||||||
|
scikit-image==0.18.3
|
||||||
|
scipy==1.7.3
|
||||||
|
setuptools-scm==6.3.2
|
||||||
|
six==1.16.0
|
||||||
|
sqlparse==0.4.2
|
||||||
|
tifffile==2021.11.2
|
||||||
|
tomli==1.2.2
|
||||||
|
torch==1.10.0
|
||||||
|
torchvision==0.11.1
|
||||||
|
typing_extensions==4.0.1
|
||||||
0
sumasen_easyocr/__init__.py
Normal file
0
sumasen_easyocr/__init__.py
Normal file
BIN
sumasen_easyocr/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
sumasen_easyocr/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
sumasen_easyocr/__pycache__/admin.cpython-39.pyc
Normal file
BIN
sumasen_easyocr/__pycache__/admin.cpython-39.pyc
Normal file
Binary file not shown.
BIN
sumasen_easyocr/__pycache__/apps.cpython-39.pyc
Normal file
BIN
sumasen_easyocr/__pycache__/apps.cpython-39.pyc
Normal file
Binary file not shown.
BIN
sumasen_easyocr/__pycache__/models.cpython-39.pyc
Normal file
BIN
sumasen_easyocr/__pycache__/models.cpython-39.pyc
Normal file
Binary file not shown.
BIN
sumasen_easyocr/__pycache__/urls.cpython-39.pyc
Normal file
BIN
sumasen_easyocr/__pycache__/urls.cpython-39.pyc
Normal file
Binary file not shown.
BIN
sumasen_easyocr/__pycache__/views.cpython-39.pyc
Normal file
BIN
sumasen_easyocr/__pycache__/views.cpython-39.pyc
Normal file
Binary file not shown.
4
sumasen_easyocr/admin.py
Normal file
4
sumasen_easyocr/admin.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from .models import Document
|
||||||
|
|
||||||
|
admin.site.register(Document)
|
||||||
6
sumasen_easyocr/apps.py
Normal file
6
sumasen_easyocr/apps.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class SumasenEasyocrConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'sumasen_easyocr'
|
||||||
31
sumasen_easyocr/migrations/0001_initial.py
Normal file
31
sumasen_easyocr/migrations/0001_initial.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Generated by Django 3.2.9 on 2021-12-02 10:05
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Document',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=512, verbose_name='name')),
|
||||||
|
('file', models.FileField(upload_to='%y/%m/%d')),
|
||||||
|
('uploaded_date', models.DateField(default=datetime.date.today)),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name_plural': 'Documents',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
0
sumasen_easyocr/migrations/__init__.py
Normal file
0
sumasen_easyocr/migrations/__init__.py
Normal file
Binary file not shown.
BIN
sumasen_easyocr/migrations/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
sumasen_easyocr/migrations/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
51
sumasen_easyocr/models.py
Normal file
51
sumasen_easyocr/models.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
from django.db import models
|
||||||
|
from django.db.models.deletion import CASCADE
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
from django.db.models.signals import post_save, post_delete
|
||||||
|
from django.dispatch import receiver
|
||||||
|
import easyocr
|
||||||
|
|
||||||
|
|
||||||
|
class Document(models.Model):
|
||||||
|
name=models.CharField(_('name'), max_length=512)
|
||||||
|
user = models.ForeignKey(User, on_delete=CASCADE)
|
||||||
|
file = models.FileField(upload_to='%y/%m/%d', blank=False)
|
||||||
|
uploaded_date = models.DateField(default=datetime.date.today)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = "Documents"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=Document)
|
||||||
|
def publish_date(sender, instance, created, **kwargs):
|
||||||
|
file = instance.file.path
|
||||||
|
file_format = os.path.basename(file).split('.')[-1]
|
||||||
|
file_name = os.path.basename(file).split('.')[0]
|
||||||
|
file_path = os.path.dirname(file)
|
||||||
|
name = instance.name
|
||||||
|
|
||||||
|
#os.remove(file)
|
||||||
|
|
||||||
|
try:
|
||||||
|
reader = easyocr.Reader(['ja','en'])
|
||||||
|
result = reader.readtext(file)
|
||||||
|
print('@@@@@@@@@@')
|
||||||
|
print(result)
|
||||||
|
print('@@@@@@@@@@')
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_delete, sender=Document)
|
||||||
|
def delete_layer(sender, instance, **kwargs):
|
||||||
|
if instance.file:
|
||||||
|
if os.path.isfile(instance.file.path):
|
||||||
|
os.remove(instance.file.path)
|
||||||
3
sumasen_easyocr/tests.py
Normal file
3
sumasen_easyocr/tests.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
BIN
sumasen_easyocr/uploaded/jp22.jpg
Normal file
BIN
sumasen_easyocr/uploaded/jp22.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 306 KiB |
7
sumasen_easyocr/urls.py
Normal file
7
sumasen_easyocr/urls.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path, re_path
|
||||||
|
from .views import FileUploadView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
re_path(r'^upload/', FileUploadView.as_view())
|
||||||
|
]
|
||||||
28
sumasen_easyocr/views.py
Normal file
28
sumasen_easyocr/views.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.parsers import MultiPartParser
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework import status
|
||||||
|
import easyocr
|
||||||
|
|
||||||
|
class FileUploadView(APIView):
|
||||||
|
parser_classes = [MultiPartParser,]
|
||||||
|
|
||||||
|
def post(self, request, format='jpg'):
|
||||||
|
up_file = request.FILES['file']
|
||||||
|
destination = open('/Users/mohamednouffer/workspace/akira_san/sumasen_ocr/sumasen_easyocr/uploaded/' + up_file.name, 'wb+')
|
||||||
|
for chunk in up_file.chunks():
|
||||||
|
destination.write(chunk)
|
||||||
|
destination.close()
|
||||||
|
|
||||||
|
try:
|
||||||
|
reader = easyocr.Reader(['ja','en'])
|
||||||
|
result = reader.readtext('/Users/mohamednouffer/workspace/akira_san/sumasen_ocr/sumasen_easyocr/uploaded/' + up_file.name)
|
||||||
|
#print('@@@@@@@@@@')
|
||||||
|
#print(result)
|
||||||
|
#print('@@@@@@@@@@')
|
||||||
|
return Response(result, status.HTTP_201_CREATED)
|
||||||
|
#return Response({''}, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return Response({'Error': "Error occured"}, status.HTTP_201_CREATED)
|
||||||
Reference in New Issue
Block a user