rakib72642 commited on
Commit
fe9d3dc
·
1 Parent(s): 7a659ab

create django structure

Browse files
data/__init__.py ADDED
File without changes
data/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
data/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class DataConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'data'
data/data.py ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ member_details = {
3
+ "munna": {
4
+ "Name": "Arifur Rahman Munna",
5
+ "Designation": "Technology Manager",
6
+ "Organization": "HawkEyes Digital Monitoring Limited",
7
+ "E-mail": "arif@hedigital.tech",
8
+ "Concact Number": "+8801571322757",
9
+ "Joining Date": "Aug-21",
10
+ "Date of Birth": "25-Dec",
11
+ "Blood Group": "O+",
12
+ "Linkedin": "https://www.linkedin.com/in/munnasorder/"
13
+ },
14
+ "rakib": {
15
+ "Name": "Md.Rakibul Hasan Naym",
16
+ "Designation": "Junior AI Engineer",
17
+ "Organization": "HawkEyes Digital Monitoring Limited",
18
+ "E-mail": "naym.mj@gmail.com",
19
+ "Concact Number": "+8801638830165",
20
+ "Joining Date": "Mar-23",
21
+ "Date of Birth": "5-Jun",
22
+ "Blood Group": "A+",
23
+ "Linkedin": "https://www.linkedin.com/in/md-rakibul-hasan-naym-625263229/"
24
+ },
25
+ "sakib": {
26
+ "Name": "Mahbubul Hasan Sakib",
27
+ "Designation": "Jr. Software Engineer(Node js)",
28
+ "Organization": "HawkEyes Digital Monitoring Limited",
29
+ "E-mail": "mahbubulhasan179@gmail.com",
30
+ "Concact Number": "+8801812346095",
31
+ "Joining Date": "May-23",
32
+ "Date of Birth": "4-Aug",
33
+ "Blood Group": "O+",
34
+ "Linkedin": "https://www.linkedin.com/in/mhsakib29/"
35
+ },
36
+ "shahadat": {
37
+ "Name": "Md. Shahadot Hossain",
38
+ "Designation": "Jr. React Native Developer",
39
+ "Organization": "HawkEyes Digital Monitoring Limited",
40
+ "E-mail": "shahadotrahat786@gmail.com",
41
+ "Concact Number": "+8801775020582",
42
+ "Joining Date": "Jun-23",
43
+ "Date of Birth": "6-Feb",
44
+ "Blood Group": "B+",
45
+ "Linkedin": "https://www.linkedin.com/in/shahadot786/"
46
+ },
47
+ "minhaz": {
48
+ "Name": "S.M. Minhazul Abedin Shouhug",
49
+ "Designation": "Jr. React Native Developer",
50
+ "Organization": "HawkEyes Digital Monitoring Limited",
51
+ "E-mail": "minhazulabedin44@gmail.com",
52
+ "Concact Number": "+880182411744",
53
+ "Joining Date": "Jun-23",
54
+ "Date of Birth": "1-Jan",
55
+ "Blood Group": "B+",
56
+ "Linkedin": "https://www.linkedin.com/in/minhaz19/"
57
+ },
58
+ "himel": {
59
+ "Name": "Mehedi Mohammad Himel",
60
+ "Designation": "Junior AI Engineer",
61
+ "Organization": "HawkEyes Digital Monitoring Limited",
62
+ "E-mail": "himel@hedigital.tech",
63
+ "Concact Number": "+8801841021211",
64
+ "Joining Date": "Jun-23",
65
+ "Date of Birth": "20-Mar",
66
+ "Blood Group": "B+",
67
+ "Linkedin": "https://www.linkedin.com/in/mm-himel/"
68
+ },
69
+ "ferdous": {
70
+ "Name": "Mirza Ferdous Ohid",
71
+ "Designation": "Managing Director & CEO",
72
+ "Organization": "HawkEyes Digital Monitoring Limited",
73
+ "E-mail": "ferdous@hedigital.tech",
74
+ "Concact Number": "+8801711081888",
75
+ "Joining Date": "****",
76
+ "Date of Birth": "21-July",
77
+ "Blood Group": "O+",
78
+ "Linkedin": "https://www.linkedin.com/in/mirza-ferdous-ohid-70b16236/"
79
+ },
80
+ "aiyub": {
81
+ "Name": "Md. Aiyubali",
82
+ "Designation": "Jr. AI Engineer",
83
+ "Organization": "HawkEyes Digital Monitoring Limited",
84
+ "E-mail": "aiyub@hedigital.tech",
85
+ "Concact Number": "01650027810",
86
+ "Joining Date": "2-Dec-23",
87
+ "Date of Birth": "4-Jan-1999",
88
+ "Blood Group": "O+",
89
+ "Linkedin": ""
90
+ },
91
+ "shanin": {
92
+ "Name": "Md Shakhawat Hossain",
93
+ "Designation": "Jr. AI Engineer",
94
+ "Organization": "HawkEyes Digital Monitoring Limited",
95
+ "E-mail": "shanin@hedigital.tech",
96
+ "Concact Number": "01778198423",
97
+ "Joining Date": "15-Jan-2023",
98
+ "Date of Birth": "15-Jun-2001",
99
+ "Blood Group": "AB+",
100
+ "Linkedin": ""
101
+ },
102
+ "walid": {
103
+ "Name": "Walid Al Hasan",
104
+ "Designation": "Intern",
105
+ "Organization": "HawkEyes Digital Monitoring Limited",
106
+ "E-mail": "walid@hedigital.tech",
107
+ "Concact Number": "01792103884",
108
+ "Joining Date": "3-Feb-2024",
109
+ "Date of Birth": "25-May-2000",
110
+ "Blood Group": "A+",
111
+ "Linkedin": ""
112
+ },
113
+ "jony": {
114
+ "Name": "Md Razikul Islam Jony",
115
+ "Designation": "Jr. Frontend Developer",
116
+ "Organization": "HawkEyes Digital Monitoring Limited",
117
+ "E-mail": "razikuljoni@gmail.com",
118
+ "Concact Number": "01623208660",
119
+ "Joining Date": "11-Feb-2024",
120
+ "Date of Birth": "24-Oct-2001",
121
+ "Blood Group": "B+",
122
+ "Linkedin": ""
123
+ },
124
+ "waliullah": {
125
+ "Name": "Md Ollullah Sardar",
126
+ "Designation": "Jr. Backend Developer",
127
+ "Organization": "HawkEyes Digital Monitoring Limited",
128
+ "E-mail": "oliullah@hedigital.tech",
129
+ "Concact Number": "01643616707",
130
+ "Joining Date": "2-Mar-2024",
131
+ "Date of Birth": "20-Jun-1998",
132
+ "Blood Group": "O+",
133
+ "Linkedin": ""
134
+ },
135
+ "sajal": {
136
+ "Name": "Mohammad Assaduzzaman",
137
+ "Designation": "Asst. Manager",
138
+ "Organization": "HawkEyes Digital Monitoring Limited",
139
+ "E-mail": "sajal@hedigital.tech",
140
+ "Concact Number": "01321119233",
141
+ "Joining Date": "17-Jan-2020",
142
+ "Date of Birth": "24-Feb-1993",
143
+ "Blood Group": "O+",
144
+ "Linkedin": ""
145
+ },
146
+ "deba": {
147
+ "Name": "Deba Prasad Mistry",
148
+ "Designation": "",
149
+ "Organization": "HawkEyes Digital Monitoring Limited",
150
+ "E-mail": "deba.hedigital@gmail.com",
151
+ "Concact Number": "01795807053",
152
+ "Joining Date": "10-Jan-2020",
153
+ "Date of Birth": "29-Dec-1995",
154
+ "Blood Group": "B+",
155
+ "Linkedin": ""
156
+ },
157
+ "nayem": {
158
+ "Name": "Saidul Alam Nayem",
159
+ "Designation": "Asst. Manager",
160
+ "Organization": "HawkEyes Digital Monitoring Limited",
161
+ "E-mail": "nayem@hedigital.tech",
162
+ "Concact Number": "01321119224",
163
+ "Joining Date": "8-Jul-2020",
164
+ "Date of Birth": "29-Jan-1995",
165
+ "Blood Group": "AB+",
166
+ "Linkedin": ""
167
+ },
168
+ "rasel": {
169
+ "Name": "Rasedul Islam Rasel",
170
+ "Designation": "Senior Executive",
171
+ "Organization": "HawkEyes Digital Monitoring Limited",
172
+ "E-mail": "rasel@hedigital.tech",
173
+ "Concact Number": "rasel@hedigital.tech",
174
+ "Joining Date": "10-Jan-2021",
175
+ "Date of Birth": "9-Jan-1994",
176
+ "Blood Group": "B+",
177
+ "Linkedin": ""
178
+ },
179
+ "sagor": {
180
+ "Name": "Md Mizanur Rahman Sagor",
181
+ "Designation": "Executive",
182
+ "Organization": "HawkEyes Digital Monitoring Limited",
183
+ "E-mail": "Sagor@hedigital.tech",
184
+ "Concact Number": "01892479942",
185
+ "Joining Date": "2-Dec-2023",
186
+ "Date of Birth": "24-Apr-1997",
187
+ "Blood Group": "O+",
188
+ "Linkedin": ""
189
+ },
190
+ "tapan": {
191
+ "Name": "Tapan Sutradhar",
192
+ "Designation": "",
193
+ "Organization": "HawkEyes Digital Monitoring Limited",
194
+ "E-mail": "tapan@hedigital.tech",
195
+ "Concact Number": "01721 294453",
196
+ "Joining Date": "23-Jul-2020",
197
+ "Date of Birth": "22-Dec-1996",
198
+ "Blood Group": "B+",
199
+ "Linkedin": ""
200
+ },
201
+ "imran": {
202
+ "Name": "Md Imran Hossain",
203
+ "Designation": "Junior Executive",
204
+ "Organization": "HawkEyes Digital Monitoring Limited",
205
+ "E-mail": "Imran@hedigital.tech",
206
+ "Concact Number": "01329709023",
207
+ "Joining Date": "2-Mar-2024",
208
+ "Date of Birth": "29-Jul-1997",
209
+ "Blood Group": "B+",
210
+ "Linkedin": ""
211
+ },
212
+ "sabuj": {
213
+ "Name": "Fakir Rabiul Islam",
214
+ "Designation": "Executive ",
215
+ "Organization": "HawkEyes Digital Monitoring Limited",
216
+ "E-mail": "rabuil.bght@gmail.com",
217
+ "Concact Number": "01722555199",
218
+ "Joining Date": "16-Nov-2023",
219
+ "Date of Birth": "6-Jun-1989",
220
+ "Blood Group": "A+",
221
+ "Linkedin": ""
222
+ },
223
+ "rahmat": {
224
+ "Name": "Md. Rahmat Ali",
225
+ "Designation": "Executive ",
226
+ "Organization": "HawkEyes Digital Monitoring Limited",
227
+ "E-mail": "rahmat@hedigital.tech",
228
+ "Concact Number": "01321119231",
229
+ "Joining Date": "12-Jan-2021",
230
+ "Date of Birth": "12-Oct-1999",
231
+ "Blood Group": "B+",
232
+ "Linkedin": ""
233
+ },
234
+ "aymun": {
235
+ "Name": "Aymun Khan",
236
+ "Designation": "Executive ",
237
+ "Organization": "HawkEyes Digital Monitoring Limited",
238
+ "E-mail": "ayman@hedigital.tech",
239
+ "Concact Number": "01329709025",
240
+ "Joining Date": "2-Jul-2023",
241
+ "Date of Birth": "31-May-1997",
242
+ "Blood Group": "O+",
243
+ "Linkedin": ""
244
+ },
245
+ "nadim": {
246
+ "Name": "Nadim Ahmmed",
247
+ "Designation": "Executive ",
248
+ "Organization": "HawkEyes Digital Monitoring Limited",
249
+ "E-mail": "nadim@hedigital.tech",
250
+ "Concact Number": "01792303497",
251
+ "Joining Date": "10-Jan-2020",
252
+ "Date of Birth": "20-Sep-1995",
253
+ "Blood Group": "B+",
254
+ "Linkedin": ""
255
+ },
256
+ "tahmid": {
257
+ "Name": "Md Tahmidur Rahman",
258
+ "Designation": "Executive ",
259
+ "Organization": "HawkEyes Digital Monitoring Limited",
260
+ "E-mail": "tahmid@hedigital.tech",
261
+ "Concact Number": "01750796337",
262
+ "Joining Date": "12-Jan-2021",
263
+ "Date of Birth": "24-Sep-1997",
264
+ "Blood Group": "B+",
265
+ "Linkedin": ""
266
+ },
267
+ "adnan": {
268
+ "Name": "M. A. Adnan",
269
+ "Designation": "Junior Executive",
270
+ "Organization": "HawkEyes Digital Monitoring Limited",
271
+ "E-mail": "adnan@hedigital.tech",
272
+ "Concact Number": "01959225011",
273
+ "Joining Date": "15-Feb-2024",
274
+ "Date of Birth": "01 June 1995",
275
+ "Blood Group": "A+",
276
+ "Linkedin": ""
277
+ },
278
+ "saidul": {
279
+ "Name": "Saidul Alam Sarker",
280
+ "Designation": "",
281
+ "Organization": "HawkEyes Digital Monitoring Limited",
282
+ "E-mail": "",
283
+ "Concact Number": "",
284
+ "Joining Date": "",
285
+ "Date of Birth": "",
286
+ "Blood Group": "",
287
+ "Linkedin": ""
288
+ }
289
+ }
data/migrations/__init__.py ADDED
File without changes
data/migrations/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (197 Bytes). View file
 
data/models.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.db import models
2
+
3
+ # Create your models here.
data/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
data/views.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.shortcuts import render
2
+
3
+ # Create your views here.
db.sqlite3 ADDED
Binary file (135 kB). View file
 
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', 'myproject.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()
model/__init__.py ADDED
File without changes
model/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
model/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class ModelConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'model'
model/faceModel.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:26362c28745a6d1b6040f46f56830c40ba159cff779424526d1470142e3b73ce
3
+ size 195280017
model/migrations/__init__.py ADDED
File without changes
model/migrations/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (198 Bytes). View file
 
model/models.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.db import models
2
+
3
+ # Create your models here.
model/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
model/views.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.shortcuts import render
2
+
3
+ # Create your views here.
myapp/__init__.py ADDED
File without changes
myapp/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
myapp/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class MyappConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'myapp'
myapp/logic.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import asyncio
3
+ from io import BytesIO
4
+ from PIL import Image
5
+ from aiohttp import ClientSession
6
+ import torch
7
+ from .model import faceModel
8
+ from data.data import member_details
9
+ import pandas as pd
10
+
11
+ async def get_image(img_url):
12
+ async with ClientSession() as session:
13
+ try:
14
+ async with session.get(img_url) as response:
15
+ img_data = await response.read()
16
+ return BytesIO(img_data)
17
+ except Exception as e:
18
+ raise ValueError(f"getImage ERROR : {str(e)}")
19
+ finally:
20
+ torch.cuda.empty_cache()
21
+
22
+ async def detection(model,img_content):
23
+ try:
24
+ img = Image.open(img_content)
25
+ result = model(img,device=0,conf=0.8)
26
+ detection = {}
27
+ data = json.loads(result[0].tojson())
28
+ if len(data) == 0:
29
+ res = {"AI": "Not Found"}
30
+ detection.update(res)
31
+ else:
32
+ df = pd.DataFrame(data)
33
+ name_counts = df['name'].value_counts().sort_index()
34
+
35
+ for name, count in name_counts.items():
36
+ res = {name: count}
37
+ detection.update(res)
38
+ return detection
39
+ except Exception as e:
40
+ raise ValueError(f"detection ERROR : {str(e)}")
41
+ finally:
42
+ torch.cuda.empty_cache()
43
+
44
+ async def format_result(ai_result):
45
+ result = {}
46
+ try:
47
+ for name, details in ai_result.items():
48
+ if name in member_details:
49
+ member_info = member_details[name]
50
+ member_info['Count'] = details
51
+ result[name] = member_info
52
+ return result
53
+ except Exception as e:
54
+ raise ValueError(f"format_result ERROR : {str(e)}")
55
+ finally:
56
+ torch.cuda.empty_cache()
57
+
58
+ async def main_detection(url):
59
+ try:
60
+ image = await get_image(url)
61
+ detect_data = await detection(faceModel, image)
62
+ result = await format_result(detect_data)
63
+ return result
64
+ except Exception as e:
65
+ raise ValueError(f"mainDet ERROR : {str(e)}")
66
+ finally:
67
+ torch.cuda.empty_cache()
68
+
myapp/migrations/0001_initial.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 5.0.4 on 2024-05-07 17:08
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ initial = True
9
+
10
+ dependencies = [
11
+ ]
12
+
13
+ operations = [
14
+ migrations.CreateModel(
15
+ name='ImageUrl',
16
+ fields=[
17
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+ ('url', models.URLField(verbose_name='Image URL')),
19
+ ('processed', models.DateTimeField(auto_now_add=True, verbose_name='Processed Time')),
20
+ ],
21
+ ),
22
+ ]
myapp/migrations/__init__.py ADDED
File without changes
myapp/migrations/__pycache__/0001_initial.cpython-312.pyc ADDED
Binary file (1.02 kB). View file
 
myapp/migrations/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (198 Bytes). View file
 
myapp/model.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from ultralytics import YOLO
2
+
3
+ faceModel = YOLO("model/faceModel.pt")
myapp/models.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from django.db import models
2
+
3
+ class ImageUrl(models.Model):
4
+ url = models.URLField(verbose_name="Image URL")
5
+ processed = models.DateTimeField(auto_now_add=True, verbose_name="Processed Time")
6
+ # You can add more fields to store results or statuses, e.g., processing status
7
+
8
+ def __str__(self):
9
+ return f"URL: {self.url} processed on {self.processed}"
myapp/serializers.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from rest_framework import serializers
2
+
3
+ class ItemSerializer(serializers.Serializer):
4
+ url = serializers.URLField(max_length=200)
5
+
6
+ def create(self, validated_data):
7
+ # Typically, you would save the data to a database here.
8
+ # As you're not using a database for this instance, you can just return the validated data.
9
+ return validated_data
10
+
11
+ def update(self, instance, validated_data):
12
+ instance.url = validated_data.get('url', instance.url)
13
+ instance.save()
14
+ return instance
myapp/tests.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from django.test import TestCase, Client
2
+ from django.urls import reverse
3
+
4
+ class SimpleTest(TestCase):
5
+ def test_details(self):
6
+ client = Client()
7
+ response = client.get(reverse('status'))
8
+ self.assertEqual(response.status_code, 200)
myapp/urls.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from django.urls import path
2
+ from .views import StatusView, TechView
3
+
4
+ urlpatterns = [
5
+ path('status/', StatusView.as_view(), name='StatusView'),
6
+ path('tech/', TechView.as_view(), name='tech'),
7
+ ]
myapp/views.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.http import JsonResponse
2
+ from django.views import View
3
+ from django.utils.decorators import method_decorator
4
+ from django.views.decorators.csrf import csrf_exempt
5
+ from rest_framework.parsers import JSONParser
6
+ from .serializers import ItemSerializer
7
+ from .logic import main_detection
8
+ from .models import ImageUrl
9
+ import json
10
+
11
+ @method_decorator(csrf_exempt, name='dispatch')
12
+ class StatusView(View):
13
+ def get(self, request):
14
+ return JsonResponse({"status": "AI Server is running"}, status=200)
15
+
16
+ @method_decorator(csrf_exempt, name='dispatch')
17
+ class TechView(View):
18
+ async def post(self, request):
19
+ try:
20
+ data = json.loads(request.body.decode('utf-8')) # Correct way to parse JSON data
21
+ except json.JSONDecodeError:
22
+ return JsonResponse({'error': 'Invalid JSON'}, status=400)
23
+
24
+ serializer = ItemSerializer(data=data)
25
+ if serializer.is_valid():
26
+ # Assuming `main_detection` is an asynchronous function you've set up
27
+ result = await main_detection(serializer.validated_data['url'])
28
+ return JsonResponse(result, safe=False, status=200)
29
+ else:
30
+ return JsonResponse(serializer.errors, status=400)
myproject/__init__.py ADDED
File without changes
myproject/asgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ASGI config for myproject 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/5.0/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', 'myproject.settings')
15
+
16
+ application = get_asgi_application()
myproject/urls.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from django.urls import path
2
+ from myapp import views
3
+
4
+ urlpatterns = [
5
+ path('status/', views.StatusView.as_view(), name='StatusView'),
6
+ path('tech/', views.TechView.as_view(), name='tech'),
7
+ # Add more paths here
8
+ ]
myproject/wsgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ WSGI config for myproject 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/5.0/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', 'myproject.settings')
15
+
16
+ application = get_wsgi_application()