init commit
This commit is contained in:
0
base/__init__.py
Normal file
0
base/__init__.py
Normal file
BIN
base/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
base/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
base/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/admin.cpython-310.pyc
Normal file
BIN
base/__pycache__/admin.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/admin.cpython-311.pyc
Normal file
BIN
base/__pycache__/admin.cpython-311.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/apps.cpython-310.pyc
Normal file
BIN
base/__pycache__/apps.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/apps.cpython-311.pyc
Normal file
BIN
base/__pycache__/apps.cpython-311.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/forms.cpython-310.pyc
Normal file
BIN
base/__pycache__/forms.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/forms.cpython-311.pyc
Normal file
BIN
base/__pycache__/forms.cpython-311.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/models.cpython-310.pyc
Normal file
BIN
base/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/models.cpython-311.pyc
Normal file
BIN
base/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/urls.cpython-310.pyc
Normal file
BIN
base/__pycache__/urls.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/urls.cpython-311.pyc
Normal file
BIN
base/__pycache__/urls.cpython-311.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/views.cpython-310.pyc
Normal file
BIN
base/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/__pycache__/views.cpython-311.pyc
Normal file
BIN
base/__pycache__/views.cpython-311.pyc
Normal file
Binary file not shown.
7
base/admin.py
Normal file
7
base/admin.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from .models import Patient, Detection
|
||||
# Register your models here.
|
||||
|
||||
|
||||
admin.site.register(Patient)
|
||||
admin.site.register(Detection)
|
||||
6
base/apps.py
Normal file
6
base/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BaseConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'base'
|
||||
18
base/forms.py
Normal file
18
base/forms.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from django import forms
|
||||
from .models import Patient
|
||||
|
||||
|
||||
class PatientCreateForm(forms.Form):
|
||||
|
||||
|
||||
name = forms.CharField()
|
||||
nationalID = forms.CharField()
|
||||
description = forms.CharField(widget=forms.Textarea)
|
||||
image = forms.ImageField(required=True)
|
||||
|
||||
|
||||
class PatientUpdateForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Patient
|
||||
fields = ('name', 'nationalID', 'description', 'image')
|
||||
25
base/migrations/0001_initial.py
Normal file
25
base/migrations/0001_initial.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-14 08:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Patient',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=50)),
|
||||
('nationalID', models.CharField(max_length=20)),
|
||||
('status', models.CharField(choices=[(0, 'Pending'), (1, 'Processing'), (2, 'Processed')], default=0, max_length=20)),
|
||||
('image', models.ImageField(upload_to='uploads/')),
|
||||
('description', models.TextField()),
|
||||
],
|
||||
),
|
||||
]
|
||||
18
base/migrations/0002_alter_patient_status.py
Normal file
18
base/migrations/0002_alter_patient_status.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-14 08:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='patient',
|
||||
name='status',
|
||||
field=models.CharField(choices=[(0, '---'), (1, 'Pending'), (2, 'Processed')], default=0, max_length=20),
|
||||
),
|
||||
]
|
||||
18
base/migrations/0003_alter_patient_status.py
Normal file
18
base/migrations/0003_alter_patient_status.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-14 08:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0002_alter_patient_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='patient',
|
||||
name='status',
|
||||
field=models.CharField(choices=[('---', '---'), ('pending', 'Pending'), ('Processed', 'Processed')], default='---', max_length=20),
|
||||
),
|
||||
]
|
||||
20
base/migrations/0004_patient_created_at.py
Normal file
20
base/migrations/0004_patient_created_at.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-14 09:02
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0003_alter_patient_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='patient',
|
||||
name='created_at',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
18
base/migrations/0005_alter_patient_image.py
Normal file
18
base/migrations/0005_alter_patient_image.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-14 09:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0004_patient_created_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='patient',
|
||||
name='image',
|
||||
field=models.ImageField(upload_to='uploads/<django.db.models.fields.CharField>'),
|
||||
),
|
||||
]
|
||||
18
base/migrations/0006_alter_patient_image.py
Normal file
18
base/migrations/0006_alter_patient_image.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-14 09:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0005_alter_patient_image'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='patient',
|
||||
name='image',
|
||||
field=models.ImageField(upload_to='static/uploads/<django.db.models.fields.CharField>'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-14 12:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0006_alter_patient_image'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='patient',
|
||||
name='description',
|
||||
field=models.CharField(max_length=500),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='patient',
|
||||
name='image',
|
||||
field=models.ImageField(upload_to='static/uploads/'),
|
||||
),
|
||||
]
|
||||
17
base/migrations/0008_remove_patient_status.py
Normal file
17
base/migrations/0008_remove_patient_status.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-14 14:56
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0007_alter_patient_description_alter_patient_image'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='patient',
|
||||
name='status',
|
||||
),
|
||||
]
|
||||
22
base/migrations/0009_detection.py
Normal file
22
base/migrations/0009_detection.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.1.6 on 2023-02-15 10:10
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0008_remove_patient_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Detection',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('dImage', models.ImageField(upload_to='static/uploads/detections/')),
|
||||
('patient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='base.patient')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
base/migrations/__init__.py
Normal file
0
base/migrations/__init__.py
Normal file
BIN
base/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
BIN
base/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
base/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
base/migrations/__pycache__/0009_detection.cpython-310.pyc
Normal file
BIN
base/migrations/__pycache__/0009_detection.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/migrations/__pycache__/0009_detection.cpython-311.pyc
Normal file
BIN
base/migrations/__pycache__/0009_detection.cpython-311.pyc
Normal file
Binary file not shown.
BIN
base/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
base/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
base/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
base/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
25
base/models.py
Normal file
25
base/models.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Patient(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
name = models.CharField(max_length=50)
|
||||
nationalID = models.CharField(max_length=20)
|
||||
image = models.ImageField(upload_to='static/uploads/')
|
||||
description = models.CharField(max_length=500)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
||||
|
||||
class Detection(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return self.patient.name
|
||||
|
||||
patient = models.ForeignKey(Patient, on_delete=models.CASCADE)
|
||||
dImage = models.ImageField(upload_to='static/uploads/detections/')
|
||||
3
base/tests.py
Normal file
3
base/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
15
base/urls.py
Normal file
15
base/urls.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.home, name='home'),
|
||||
path('search/', views.search, name='patient_search'),
|
||||
path('create/', views.patient_create, name='patient_create'),
|
||||
path('delete/<int:id>/', views.patient_delete, name='patient_delete'),
|
||||
path('update/<int:id>/', views.patient_update, name='patient_update'),
|
||||
path('detect/<int:id>/', views.patient_detect, name='patient_detect'),
|
||||
path('detect/', views.detect_list, name='detect_list'),
|
||||
path('detect/<int:id>', views.detect_view, name='detect_view'),
|
||||
path('detect/delete/<int:id>', views.detect_delete, name='detect_delete')
|
||||
|
||||
]
|
||||
137
base/views.py
Normal file
137
base/views.py
Normal file
@@ -0,0 +1,137 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from .models import Patient, Detection
|
||||
from .forms import PatientCreateForm, PatientUpdateForm
|
||||
from django.contrib import messages
|
||||
from datetime import datetime
|
||||
from django.db.models import Q
|
||||
import subprocess
|
||||
import os
|
||||
from PIL import Image
|
||||
import shutil
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def home(requset):
|
||||
|
||||
patients = Patient.objects.all().order_by('-created_at')
|
||||
|
||||
return render(requset, 'index.html', {'patients' : patients})
|
||||
|
||||
|
||||
def search(request):
|
||||
|
||||
patients = Patient.objects.filter(
|
||||
Q(name__contains=request.GET.get('query')) |
|
||||
Q(nationalID__contains=request.GET.get('query'))
|
||||
).order_by('-created_at')
|
||||
|
||||
print('request : ', request)
|
||||
|
||||
return render(request, 'index.html', {'patients': patients})
|
||||
|
||||
|
||||
def patient_create(request):
|
||||
if request.method == 'POST':
|
||||
print('here')
|
||||
form = PatientCreateForm(request.POST, request.FILES)
|
||||
print(form)
|
||||
if form.is_valid():
|
||||
cd = form.cleaned_data
|
||||
Patient.objects.create(
|
||||
name = cd['name'],
|
||||
nationalID = cd['nationalID'],
|
||||
image = cd['image'],
|
||||
description = cd['description'],
|
||||
created_at = datetime.now
|
||||
)
|
||||
messages.success(request, 'Patient added successfully')
|
||||
|
||||
return redirect('home')
|
||||
else:
|
||||
form = PatientCreateForm()
|
||||
return render(request, 'patient_create.html', {'form': form})
|
||||
|
||||
|
||||
def patient_delete(request, id):
|
||||
patient = Patient.objects.get(id=id).delete()
|
||||
messages.success(request, 'Patient deleted successfully')
|
||||
return redirect('home')
|
||||
|
||||
|
||||
|
||||
def patient_update(request, id):
|
||||
patient = Patient.objects.get(id=id)
|
||||
if request.method == 'POST':
|
||||
form = PatientUpdateForm(request.POST,request.FILES, instance=patient)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, 'Patient updated successfully')
|
||||
return redirect('home')
|
||||
else:
|
||||
form = PatientUpdateForm(instance=patient)
|
||||
return render(request, 'patient_update.html', {'form': form})
|
||||
|
||||
|
||||
|
||||
def patient_detect(request, id):
|
||||
patient = Patient.objects.get(id=id)
|
||||
|
||||
|
||||
# os.system('python detect.py --weights last.pt --img 640 --conf 0.25 --source '+ str(patient.image))
|
||||
|
||||
command = ['python', 'yolov5/detect.py', '--weights', 'last.pt', '--img', '640', '--conf', '0.25', '--source', str(patient.image)]
|
||||
|
||||
subprocess.check_output(command)
|
||||
|
||||
directory = 'yolov5/runs/detect/'
|
||||
|
||||
detected_file_dir = directory + 'exp' + str(len([f for f in os.listdir(directory) if os.path.isdir(os.path.join(directory, f))]))
|
||||
|
||||
image_name = os.path.basename(str(patient.image))
|
||||
|
||||
source_file = detected_file_dir + '/' + image_name
|
||||
|
||||
destination_file = 'static/uploads/detections/' + image_name
|
||||
|
||||
shutil.copy(source_file, destination_file)
|
||||
|
||||
detection = Detection.objects.filter(patient = patient)
|
||||
|
||||
if detection.exists():
|
||||
|
||||
detection = detection[0]
|
||||
|
||||
detection.dImage = destination_file
|
||||
|
||||
detection.save()
|
||||
|
||||
else:
|
||||
Detection.objects.create(
|
||||
|
||||
patient = patient,
|
||||
dImage = destination_file
|
||||
|
||||
)
|
||||
|
||||
detections = Detection.objects.all()
|
||||
|
||||
return render(request, 'detect_list.html', {'detections' : detections})
|
||||
|
||||
|
||||
def detect_list(request):
|
||||
detections = Detection.objects.all()
|
||||
|
||||
return render(request, 'detect_list.html', {'detections' : detections})
|
||||
|
||||
def detect_view(request, id):
|
||||
detection = Detection.objects.get(id=id)
|
||||
|
||||
return render(request, 'detect_view.html', {'detection' : detection})
|
||||
|
||||
|
||||
def detect_delete(request, id):
|
||||
detection = Detection.objects.get(id=id).delete()
|
||||
messages.success(request, 'Detection deleted successfully')
|
||||
return redirect('detect_list')
|
||||
13
base/yolov5.code-workspace
Normal file
13
base/yolov5.code-workspace
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"name": "yolov5",
|
||||
"path": "../../../Teeth Project/final_teeth/yolov5"
|
||||
},
|
||||
{
|
||||
"name": "teeth",
|
||||
"path": ".."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
||||
Reference in New Issue
Block a user