Spaces:
Sleeping
Sleeping
Commit
·
689ef7e
1
Parent(s):
8d4b6bd
Upload 23 files
Browse files- Dockerfile +15 -0
- IslBackend/__init__.py +0 -0
- IslBackend/asgi.py +16 -0
- IslBackend/settings.py +158 -0
- IslBackend/urls.py +25 -0
- IslBackend/wsgi.py +16 -0
- Pipfile +13 -0
- Pipfile.lock +61 -0
- api/__init__.py +0 -0
- api/admin.py +3 -0
- api/apps.py +6 -0
- api/migrations/__init__.py +0 -0
- api/mlModel/0.jpg +0 -0
- api/mlModel/CNN.h5 +3 -0
- api/mlModel/model.h5 +3 -0
- api/mlModel/model2.0.h5 +3 -0
- api/models.py +3 -0
- api/templates/predict.html +5 -0
- api/tests.py +3 -0
- api/views.py +122 -0
- db.sqlite3 +0 -0
- manage.py +22 -0
- nohup.out +0 -0
Dockerfile
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.11-slim-bullseye
|
2 |
+
|
3 |
+
RUN mkdir -p /home/isl-backend
|
4 |
+
|
5 |
+
WORKDIR /home/isl-backend
|
6 |
+
|
7 |
+
COPY . .
|
8 |
+
|
9 |
+
RUN apt update
|
10 |
+
|
11 |
+
RUN pip install tensorflow --no-cache-dir
|
12 |
+
|
13 |
+
RUN pip3 install django Pillow django-sslserver opencv-python tensorflow_hub scikit-learn django-cors-headers
|
14 |
+
|
15 |
+
CMD ["python" , "manage.py" , "runserver" , "0.0.0.0:7860"]
|
IslBackend/__init__.py
ADDED
File without changes
|
IslBackend/asgi.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
ASGI config for IslBackend project.
|
3 |
+
|
4 |
+
It exposes the ASGI callable as a module-level variable named ``application``.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
|
8 |
+
"""
|
9 |
+
|
10 |
+
import os
|
11 |
+
|
12 |
+
from django.core.asgi import get_asgi_application
|
13 |
+
|
14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IslBackend.settings')
|
15 |
+
|
16 |
+
application = get_asgi_application()
|
IslBackend/settings.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Django settings for IslBackend project.
|
3 |
+
|
4 |
+
Generated by 'django-admin startproject' using Django 4.1.6.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/4.1/topics/settings/
|
8 |
+
|
9 |
+
For the full list of settings and their values, see
|
10 |
+
https://docs.djangoproject.com/en/4.1/ref/settings/
|
11 |
+
"""
|
12 |
+
|
13 |
+
from pathlib import Path
|
14 |
+
|
15 |
+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
16 |
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
17 |
+
|
18 |
+
|
19 |
+
# Quick-start development settings - unsuitable for production
|
20 |
+
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
|
21 |
+
|
22 |
+
# SECURITY WARNING: keep the secret key used in production secret!
|
23 |
+
SECRET_KEY = 'django-insecure-k0wkaith=txb6hxf&d(-nf5w@nkkon-nlc5db2k=-*oh037ipx'
|
24 |
+
|
25 |
+
# SECURITY WARNING: don't run with debug turned on in production!
|
26 |
+
DEBUG = True
|
27 |
+
|
28 |
+
ALLOWED_HOSTS = ['*']
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
CORS_ALLOW_ALL_ORIGINS = True # If this is used then `CORS_ALLOWED_ORIGINS` will not have any effect
|
36 |
+
CORS_ALLOW_CREDENTIALS = True
|
37 |
+
CORS_ALLOWED_ORIGINS = [
|
38 |
+
'http://localhost:3000',
|
39 |
+
] # If this is used, then not need to use `CORS_ALLOW_ALL_ORIGINS = True`
|
40 |
+
CORS_ALLOWED_ORIGIN_REGEXES = [
|
41 |
+
'http://localhost:3000',
|
42 |
+
]
|
43 |
+
CORS_ORIGIN_WHITELIST = [
|
44 |
+
'http://localhost:3000', # for localhost (REACT Default)
|
45 |
+
'http://192.168.10.45:3000', # for network
|
46 |
+
]
|
47 |
+
|
48 |
+
CSRF_TRUSTED_ORIGINS = ['http://localhost:3000']
|
49 |
+
|
50 |
+
CORS_ALLOW_HEADERS = [
|
51 |
+
'accept',
|
52 |
+
'accept-encoding',
|
53 |
+
'authorization',
|
54 |
+
'content-type',
|
55 |
+
'dnt',
|
56 |
+
'origin',
|
57 |
+
'user-agent',
|
58 |
+
'x-csrftoken',
|
59 |
+
'x-requested-with',
|
60 |
+
]
|
61 |
+
|
62 |
+
# Application definition
|
63 |
+
|
64 |
+
INSTALLED_APPS = [
|
65 |
+
'django.contrib.admin',
|
66 |
+
'django.contrib.auth',
|
67 |
+
'django.contrib.contenttypes',
|
68 |
+
'django.contrib.sessions',
|
69 |
+
'django.contrib.messages',
|
70 |
+
'django.contrib.staticfiles',
|
71 |
+
'api',
|
72 |
+
'corsheaders',
|
73 |
+
"sslserver",
|
74 |
+
]
|
75 |
+
|
76 |
+
MIDDLEWARE = [
|
77 |
+
'corsheaders.middleware.CorsMiddleware',
|
78 |
+
'django.middleware.security.SecurityMiddleware',
|
79 |
+
'django.contrib.sessions.middleware.SessionMiddleware',
|
80 |
+
'django.middleware.common.CommonMiddleware',
|
81 |
+
'django.middleware.csrf.CsrfViewMiddleware',
|
82 |
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
83 |
+
'django.contrib.messages.middleware.MessageMiddleware',
|
84 |
+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
85 |
+
]
|
86 |
+
|
87 |
+
ROOT_URLCONF = 'IslBackend.urls'
|
88 |
+
|
89 |
+
TEMPLATES = [
|
90 |
+
{
|
91 |
+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
92 |
+
'DIRS': [],
|
93 |
+
'APP_DIRS': True,
|
94 |
+
'OPTIONS': {
|
95 |
+
'context_processors': [
|
96 |
+
'django.template.context_processors.debug',
|
97 |
+
'django.template.context_processors.request',
|
98 |
+
'django.contrib.auth.context_processors.auth',
|
99 |
+
'django.contrib.messages.context_processors.messages',
|
100 |
+
],
|
101 |
+
},
|
102 |
+
},
|
103 |
+
]
|
104 |
+
|
105 |
+
WSGI_APPLICATION = 'IslBackend.wsgi.application'
|
106 |
+
|
107 |
+
|
108 |
+
# Database
|
109 |
+
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
110 |
+
|
111 |
+
DATABASES = {
|
112 |
+
'default': {
|
113 |
+
'ENGINE': 'django.db.backends.sqlite3',
|
114 |
+
'NAME': BASE_DIR / 'db.sqlite3',
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
|
119 |
+
# Password validation
|
120 |
+
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
|
121 |
+
|
122 |
+
AUTH_PASSWORD_VALIDATORS = [
|
123 |
+
{
|
124 |
+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
125 |
+
},
|
126 |
+
{
|
127 |
+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
128 |
+
},
|
129 |
+
{
|
130 |
+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
131 |
+
},
|
132 |
+
{
|
133 |
+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
134 |
+
},
|
135 |
+
]
|
136 |
+
|
137 |
+
|
138 |
+
# Internationalization
|
139 |
+
# https://docs.djangoproject.com/en/4.1/topics/i18n/
|
140 |
+
|
141 |
+
LANGUAGE_CODE = 'en-us'
|
142 |
+
|
143 |
+
TIME_ZONE = 'UTC'
|
144 |
+
|
145 |
+
USE_I18N = True
|
146 |
+
|
147 |
+
USE_TZ = True
|
148 |
+
|
149 |
+
|
150 |
+
# Static files (CSS, JavaScript, Images)
|
151 |
+
# https://docs.djangoproject.com/en/4.1/howto/static-files/
|
152 |
+
|
153 |
+
STATIC_URL = 'static/'
|
154 |
+
|
155 |
+
# Default primary key field type
|
156 |
+
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
157 |
+
|
158 |
+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
IslBackend/urls.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""IslBackend URL Configuration
|
2 |
+
|
3 |
+
The `urlpatterns` list routes URLs to views. For more information please see:
|
4 |
+
https://docs.djangoproject.com/en/4.1/topics/http/urls/
|
5 |
+
Examples:
|
6 |
+
Function views
|
7 |
+
1. Add an import: from my_app import views
|
8 |
+
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
9 |
+
Class-based views
|
10 |
+
1. Add an import: from other_app.views import Home
|
11 |
+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
12 |
+
Including another URLconf
|
13 |
+
1. Import the include() function: from django.urls import include, path
|
14 |
+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
15 |
+
"""
|
16 |
+
from django.contrib import admin
|
17 |
+
from django.urls import path
|
18 |
+
from api import views
|
19 |
+
|
20 |
+
urlpatterns = [
|
21 |
+
path('admin/', admin.site.urls),
|
22 |
+
path('predict/', views.predict, name='predict'),
|
23 |
+
path('predictV2/', views.predictV2, name='predictV2'),
|
24 |
+
path('form/',views.form_view,name='form_view'),
|
25 |
+
]
|
IslBackend/wsgi.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
WSGI config for IslBackend project.
|
3 |
+
|
4 |
+
It exposes the WSGI callable as a module-level variable named ``application``.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
|
8 |
+
"""
|
9 |
+
|
10 |
+
import os
|
11 |
+
|
12 |
+
from django.core.wsgi import get_wsgi_application
|
13 |
+
|
14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IslBackend.settings')
|
15 |
+
|
16 |
+
application = get_wsgi_application()
|
Pipfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[[source]]
|
2 |
+
url = "https://pypi.org/simple"
|
3 |
+
verify_ssl = true
|
4 |
+
name = "pypi"
|
5 |
+
|
6 |
+
[packages]
|
7 |
+
django = "*"
|
8 |
+
django-cors-headers = "*"
|
9 |
+
|
10 |
+
[dev-packages]
|
11 |
+
|
12 |
+
[requires]
|
13 |
+
python_version = "*"
|
Pipfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_meta": {
|
3 |
+
"hash": {
|
4 |
+
"sha256": "823916835b8992d22fb0ab87787f2d151ee7815263c825a62892056c565f2a05"
|
5 |
+
},
|
6 |
+
"pipfile-spec": 6,
|
7 |
+
"requires": {
|
8 |
+
"python_version": "*"
|
9 |
+
},
|
10 |
+
"sources": [
|
11 |
+
{
|
12 |
+
"name": "pypi",
|
13 |
+
"url": "https://pypi.org/simple",
|
14 |
+
"verify_ssl": true
|
15 |
+
}
|
16 |
+
]
|
17 |
+
},
|
18 |
+
"default": {
|
19 |
+
"asgiref": {
|
20 |
+
"hashes": [
|
21 |
+
"sha256:89b2ef2247e3b562a16eef663bc0e2e703ec6468e2fa8a5cd61cd449786d4f6e",
|
22 |
+
"sha256:9e0ce3aa93a819ba5b45120216b23878cf6e8525eb3848653452b4192b92afed"
|
23 |
+
],
|
24 |
+
"markers": "python_version >= '3.7'",
|
25 |
+
"version": "==3.7.2"
|
26 |
+
},
|
27 |
+
"django": {
|
28 |
+
"hashes": [
|
29 |
+
"sha256:7e4225ec065e0f354ccf7349a22d209de09cc1c074832be9eb84c51c1799c432",
|
30 |
+
"sha256:860ae6a138a238fc4f22c99b52f3ead982bb4b1aad8c0122bcd8c8a3a02e409d"
|
31 |
+
],
|
32 |
+
"index": "pypi",
|
33 |
+
"version": "==4.2.4"
|
34 |
+
},
|
35 |
+
"django-cors-headers": {
|
36 |
+
"hashes": [
|
37 |
+
"sha256:9ada212b0e2efd4a5e339360ffc869cb21ac5605e810afe69f7308e577ea5bde",
|
38 |
+
"sha256:f9749c6410fe738278bc2b6ef17f05195bc7b251693c035752d8257026af024f"
|
39 |
+
],
|
40 |
+
"index": "pypi",
|
41 |
+
"version": "==4.2.0"
|
42 |
+
},
|
43 |
+
"sqlparse": {
|
44 |
+
"hashes": [
|
45 |
+
"sha256:5430a4fe2ac7d0f93e66f1efc6e1338a41884b7ddf2a350cedd20ccc4d9d28f3",
|
46 |
+
"sha256:d446183e84b8349fa3061f0fe7f06ca94ba65b426946ffebe6e3e8295332420c"
|
47 |
+
],
|
48 |
+
"markers": "python_version >= '3.5'",
|
49 |
+
"version": "==0.4.4"
|
50 |
+
},
|
51 |
+
"tzdata": {
|
52 |
+
"hashes": [
|
53 |
+
"sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a",
|
54 |
+
"sha256:7e65763eef3120314099b6939b5546db7adce1e7d6f2e179e3df563c70511eda"
|
55 |
+
],
|
56 |
+
"markers": "sys_platform == 'win32'",
|
57 |
+
"version": "==2023.3"
|
58 |
+
}
|
59 |
+
},
|
60 |
+
"develop": {}
|
61 |
+
}
|
api/__init__.py
ADDED
File without changes
|
api/admin.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
|
3 |
+
# Register your models here.
|
api/apps.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.apps import AppConfig
|
2 |
+
|
3 |
+
|
4 |
+
class ApiConfig(AppConfig):
|
5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
6 |
+
name = 'api'
|
api/migrations/__init__.py
ADDED
File without changes
|
api/mlModel/0.jpg
ADDED
![]() |
api/mlModel/CNN.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9f24004bbb6659063d9e0f4262f7c51ebd20f164d13b1587d33baf32bd403343
|
3 |
+
size 41237590
|
api/mlModel/model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:edb19be53a4988bc33fd49e1782975b39eb9b8d2d3fb495fb246e62356bc1ccf
|
3 |
+
size 2344628
|
api/mlModel/model2.0.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c7485d1d5ea519da8245db4f522978fae66c90dc7d2a1a5ba2e7ec4b862fcf19
|
3 |
+
size 18612080
|
api/models.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.db import models
|
2 |
+
|
3 |
+
# Create your models here.
|
api/templates/predict.html
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<form method="post" enctype="multipart/form-data">
|
2 |
+
{% csrf_token %}
|
3 |
+
<input type="file" name="image">
|
4 |
+
<button type="submit">Predict</button>
|
5 |
+
</form>
|
api/tests.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.test import TestCase
|
2 |
+
|
3 |
+
# Create your tests here.
|
api/views.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.shortcuts import render
|
2 |
+
from django.http import JsonResponse
|
3 |
+
import tensorflow as tf
|
4 |
+
import tensorflow_hub as hub
|
5 |
+
from tensorflow import keras
|
6 |
+
from PIL import Image,ImageOps
|
7 |
+
import numpy as np
|
8 |
+
import cv2 as cv
|
9 |
+
from tensorflow.keras import preprocessing
|
10 |
+
from tensorflow.keras.models import load_model
|
11 |
+
from tensorflow.keras.activations import softmax
|
12 |
+
from sklearn.preprocessing import OneHotEncoder
|
13 |
+
import os
|
14 |
+
import h5py
|
15 |
+
from django.views.decorators.csrf import csrf_exempt
|
16 |
+
|
17 |
+
model = tf.keras.models.load_model('api/mlModel/model.h5')
|
18 |
+
shape = ((50,50,3))
|
19 |
+
model = tf.keras.Sequential([hub.KerasLayer(model,input_shape=shape)])
|
20 |
+
|
21 |
+
modelV2 = tf.keras.models.load_model('api/mlModel/model2.0.h5')
|
22 |
+
|
23 |
+
@csrf_exempt
|
24 |
+
def predict(request):
|
25 |
+
if request.method == 'POST':
|
26 |
+
|
27 |
+
#image = Image.open("api/mlModel/0.jpg")
|
28 |
+
|
29 |
+
# Get the image from the request
|
30 |
+
print(request.FILES['image'])
|
31 |
+
image = Image.open(request.FILES['image'])
|
32 |
+
|
33 |
+
# Preprocess the image
|
34 |
+
|
35 |
+
test_image = image.resize((50,50))
|
36 |
+
test_image = preprocessing.image.img_to_array(test_image)
|
37 |
+
test_image = test_image / 255
|
38 |
+
test_image = np.expand_dims(test_image, axis =0)
|
39 |
+
class_names = ['1','2','3' ,'4', '5', '6' ,'7' ,'8' ,'9' ,'A' ,'B' ,'C' ,'D' ,'E' ,'F', 'G', 'H', 'I', 'J', 'K' ,'L' ,'M', 'N', 'O' ,'P' ,'Q', 'R' ,'S', 'T', 'U' ,'V' ,'W' ,'X' ,'Y' ,'Z']
|
40 |
+
|
41 |
+
# Make a prediction
|
42 |
+
predictions = model.predict(test_image)
|
43 |
+
scores = tf.nn.softmax(predictions[0])
|
44 |
+
scores = scores.numpy()
|
45 |
+
image_class = class_names[np.argmax(scores)]
|
46 |
+
print(image_class)
|
47 |
+
|
48 |
+
return JsonResponse({'prediction': image_class})
|
49 |
+
|
50 |
+
else:
|
51 |
+
return render(request,'predict.html')
|
52 |
+
|
53 |
+
|
54 |
+
# Create your views here.
|
55 |
+
|
56 |
+
def form_view(request):
|
57 |
+
return render(request,'predict.html')
|
58 |
+
|
59 |
+
@csrf_exempt
|
60 |
+
def predictV2(request):
|
61 |
+
if request.method == 'POST':
|
62 |
+
|
63 |
+
#image = Image.open("api/mlModel/0.jpg")
|
64 |
+
|
65 |
+
# Get the image from the request
|
66 |
+
print(request.FILES['image'])
|
67 |
+
#image1 = Image.open(request.FILES['image'])
|
68 |
+
#img = cv.imread(Image.open(request.FILES['image']))
|
69 |
+
img = cv.imdecode(np.fromstring(request.FILES['image'].read(), np.uint8), cv.IMREAD_UNCHANGED)
|
70 |
+
# Preprocess the image
|
71 |
+
|
72 |
+
resized_img = cv.resize(img, (250, 250), interpolation=cv.INTER_CUBIC)
|
73 |
+
resized_img.shape
|
74 |
+
#plt.imshow(resized_img)
|
75 |
+
img = resized_img
|
76 |
+
pred = modelV2.predict(x = np.array(img).reshape(-1,250,250,3)).flatten()
|
77 |
+
|
78 |
+
enc = OneHotEncoder()
|
79 |
+
enc.fit([['6'],
|
80 |
+
['K'],
|
81 |
+
['L'],
|
82 |
+
['R'],
|
83 |
+
['V'],
|
84 |
+
['3'],
|
85 |
+
['F'],
|
86 |
+
['M'],
|
87 |
+
['J'],
|
88 |
+
['0'],
|
89 |
+
['9'],
|
90 |
+
['U'],
|
91 |
+
['8'],
|
92 |
+
['P'],
|
93 |
+
['W'],
|
94 |
+
['Q'],
|
95 |
+
['N'],
|
96 |
+
['E'],
|
97 |
+
['Y'],
|
98 |
+
['H'],
|
99 |
+
['1'],
|
100 |
+
['X'],
|
101 |
+
['C'],
|
102 |
+
['G'],
|
103 |
+
['5'],
|
104 |
+
['O'],
|
105 |
+
['S'],
|
106 |
+
['B'],
|
107 |
+
['2'],
|
108 |
+
['7'],
|
109 |
+
['D'],
|
110 |
+
['T'],
|
111 |
+
['4'],
|
112 |
+
['I'],
|
113 |
+
['A'],
|
114 |
+
['Z']])
|
115 |
+
out = enc.inverse_transform(pred.reshape(1,-1))
|
116 |
+
print(out[0][0])
|
117 |
+
|
118 |
+
|
119 |
+
return JsonResponse({'prediction': out[0][0]})
|
120 |
+
|
121 |
+
else:
|
122 |
+
return render(request,'predict.html')
|
db.sqlite3
ADDED
File without changes
|
manage.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
"""Django's command-line utility for administrative tasks."""
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
|
6 |
+
|
7 |
+
def main():
|
8 |
+
"""Run administrative tasks."""
|
9 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IslBackend.settings')
|
10 |
+
try:
|
11 |
+
from django.core.management import execute_from_command_line
|
12 |
+
except ImportError as exc:
|
13 |
+
raise ImportError(
|
14 |
+
"Couldn't import Django. Are you sure it's installed and "
|
15 |
+
"available on your PYTHONPATH environment variable? Did you "
|
16 |
+
"forget to activate a virtual environment?"
|
17 |
+
) from exc
|
18 |
+
execute_from_command_line(sys.argv)
|
19 |
+
|
20 |
+
|
21 |
+
if __name__ == '__main__':
|
22 |
+
main()
|
nohup.out
ADDED
Binary file (282 kB). View file
|
|