diff --git a/MisplaceAI/Dockerfile b/MisplaceAI/Dockerfile index bbeaee31e95f39b4c64319e63cc11104bae8b118..75bc76080b6ed65c800b45f3a8ea52e4cf3681a3 100644 --- a/MisplaceAI/Dockerfile +++ b/MisplaceAI/Dockerfile @@ -1,5 +1,4 @@ -#Dockerfile -# Use the full Python runtime as a parent image +# Dockerfile FROM python:3.10 # Set the working directory in the container @@ -15,15 +14,28 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libblas-dev \ liblapack-dev \ libatlas-base-dev \ + protobuf-compiler \ + git \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies +COPY requirements.txt /app/requirements.txt RUN pip install --no-cache-dir -r requirements.txt +# Install TensorFlow Object Detection API (this assumes models directory is already present) +RUN cd /app/models/research \ + && protoc object_detection/protos/*.proto --python_out=. \ + && cp object_detection/packages/tf2/setup.py . \ + && python -m pip install . + +# Set PYTHONPATH +ENV PYTHONPATH=$PYTHONPATH:/app/models:/app/models/research:/app/models/research/slim + +# Create the media directory +RUN mkdir -p /app/media + # Expose port 8000 for the Django app EXPOSE 8000 # Run the Django server CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] - - diff --git a/MisplaceAI/MisplaceAI/__pycache__/settings.cpython-310.pyc b/MisplaceAI/MisplaceAI/__pycache__/settings.cpython-310.pyc index 7769e77d63722a1403bc1903da555cc4c5e5fa81..b7655d4edfc9a06ebba39bc17462088eb74dbd78 100644 Binary files a/MisplaceAI/MisplaceAI/__pycache__/settings.cpython-310.pyc and b/MisplaceAI/MisplaceAI/__pycache__/settings.cpython-310.pyc differ diff --git a/MisplaceAI/MisplaceAI/__pycache__/settings.cpython-39.pyc b/MisplaceAI/MisplaceAI/__pycache__/settings.cpython-39.pyc index 908ecfc16a21024070a9a52169a3b060fd2485a1..800225a3dcd23ba86d3cdc2f6ecc0302b08b130d 100644 Binary files a/MisplaceAI/MisplaceAI/__pycache__/settings.cpython-39.pyc and b/MisplaceAI/MisplaceAI/__pycache__/settings.cpython-39.pyc differ diff --git a/MisplaceAI/MisplaceAI/__pycache__/urls.cpython-310.pyc b/MisplaceAI/MisplaceAI/__pycache__/urls.cpython-310.pyc index 1d9b76ccc5bfb133824986fa4ca1a22a3ea17785..fe706b3e1c9f64ebb2356131a5e04b7d63e93087 100644 Binary files a/MisplaceAI/MisplaceAI/__pycache__/urls.cpython-310.pyc and b/MisplaceAI/MisplaceAI/__pycache__/urls.cpython-310.pyc differ diff --git a/MisplaceAI/MisplaceAI/__pycache__/urls.cpython-39.pyc b/MisplaceAI/MisplaceAI/__pycache__/urls.cpython-39.pyc index ca21d865f36b19dcd688c5f867e9b328b683660d..9c2fe688bc97c221bbc5ad59cd1357a1948b2bfd 100644 Binary files a/MisplaceAI/MisplaceAI/__pycache__/urls.cpython-39.pyc and b/MisplaceAI/MisplaceAI/__pycache__/urls.cpython-39.pyc differ diff --git a/MisplaceAI/MisplaceAI/settings.py b/MisplaceAI/MisplaceAI/settings.py index 5d11dec4dfb81b71707ecf3d8867c097ac35d0c2..b6afaac3a371d2098d1d467f9e1b9055a0a14a52 100644 --- a/MisplaceAI/MisplaceAI/settings.py +++ b/MisplaceAI/MisplaceAI/settings.py @@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/4.0/ref/settings/ """ from pathlib import Path +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -23,12 +24,17 @@ BASE_DIR = Path(__file__).resolve().parent.parent # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-34gsb7^)t!ltchc4#2^sn_#+$(4i=ts107$(2yjy#ung+%mrn2' + +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + + # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = [] @@ -45,6 +51,11 @@ INSTALLED_APPS = [ 'authentication.apps.AuthenticationConfig', 'core.apps.CoreConfig', 'admin_app.apps.AdminAppConfig', + 'item_detector.apps.ItemDetectorConfig', + 'placement_rules.apps.PlacementRulesConfig', + 'results_viewer.apps.ResultsViewerConfig', + 'process_misplaced_manager.apps.ProcessMisplacedManagerConfig', + ] MIDDLEWARE = [ @@ -141,3 +152,4 @@ STATICFILES_DIRS = [ # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + diff --git a/MisplaceAI/MisplaceAI/urls.py b/MisplaceAI/MisplaceAI/urls.py index 445aa5cca5bd38e3289f7cc3206dbbd25d39146c..6687cd0521df435f48b588e2f01b02e19255e731 100644 --- a/MisplaceAI/MisplaceAI/urls.py +++ b/MisplaceAI/MisplaceAI/urls.py @@ -1,3 +1,7 @@ +# MisplaceAI/urls.py + +from django.conf import settings +from django.conf.urls.static import static from django.contrib import admin from django.urls import path, include @@ -7,5 +11,14 @@ urlpatterns = [ path('rules/', include('rules.urls')), path('auth/', include('authentication.urls')), path('admin-app/', include('admin_app.urls')), + path('process_misplaced_manager/', include('process_misplaced_manager.urls', namespace='process_misplaced_manager')), # Ensure namespace is included correctly + path('item_detector/', include('item_detector.urls', namespace='item_detector')), # Include item_detector URLs with namespace + + ] + + + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/MisplaceAI/core/templates/core/navbar.html b/MisplaceAI/core/templates/core/navbar.html index 5a0c5f3fc08939625cd2a2bad2201eefb981c582..12bd44095a198ba9c70df720d713364abe5838a4 100644 --- a/MisplaceAI/core/templates/core/navbar.html +++ b/MisplaceAI/core/templates/core/navbar.html @@ -9,8 +9,12 @@ <li class="nav-item"> <a class="nav-link" href="{% url 'home' %}">Home</a> </li> + <!-- Add link to the image upload page --> + <li class="nav-item"> + <a class="nav-link" href="{% url 'process_misplaced_manager:upload_image' %}">Upload Image</a> + </li> {% if user.is_authenticated %} - {% if user.is_staff %} {# Check if the user is a staff member (admin) #} + {% if user.is_staff %} <li class="nav-item"> <a class="nav-link" href="{% url 'admin_dashboard' %}">Admin Dashboard</a> </li> diff --git a/MisplaceAI/docker-compose.yml b/MisplaceAI/docker-compose.yml index dc72d67c1858994e704915f2609af6280f52ef7b..14ed08a921be340552864a1188b5310d59f5adc0 100644 --- a/MisplaceAI/docker-compose.yml +++ b/MisplaceAI/docker-compose.yml @@ -7,6 +7,7 @@ services: command: python manage.py runserver 0.0.0.0:8000 volumes: - .:/app + - ./media:/app/media ports: - "8000:8000" depends_on: diff --git a/MisplaceAI/item_detector/__init__.py b/MisplaceAI/item_detector/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/MisplaceAI/item_detector/admin.py b/MisplaceAI/item_detector/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/MisplaceAI/item_detector/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/MisplaceAI/item_detector/apps.py b/MisplaceAI/item_detector/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..9f89fa27ed3f499c0c0a6f3cbde4ce0fadeb8469 --- /dev/null +++ b/MisplaceAI/item_detector/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + +class ItemDetectorConfig(AppConfig): + name = 'item_detector' + verbose_name = 'Item Detector' diff --git a/MisplaceAI/item_detector/models.py b/MisplaceAI/item_detector/models.py new file mode 100644 index 0000000000000000000000000000000000000000..38fc6067d96dcf66c07181616568db6236d6d8d3 --- /dev/null +++ b/MisplaceAI/item_detector/models.py @@ -0,0 +1,13 @@ +#item_detector/models.py +from django.db import models + +class DetectedObject(models.Model): + class_name = models.CharField(max_length=255) + ymin = models.FloatField() + xmin = models.FloatField() + ymax = models.FloatField() + xmax = models.FloatField() + image = models.ForeignKey('process_misplaced_manager.UploadedImage', on_delete=models.CASCADE) + + def __str__(self): + return f"{self.class_name} ({self.ymin}, {self.xmin}, {self.ymax}, {self.xmax})" diff --git a/MisplaceAI/item_detector/templates/item_detector/results.html b/MisplaceAI/item_detector/templates/item_detector/results.html new file mode 100644 index 0000000000000000000000000000000000000000..4505599b7bdfe9775bc441ee3515c02f3ca2b4fd --- /dev/null +++ b/MisplaceAI/item_detector/templates/item_detector/results.html @@ -0,0 +1,24 @@ +{% extends 'core/base.html' %} + +{% block content %} +<h2>Detected Objects</h2> +<div class="image-container"> + <img src="{{ output_image_url }}" alt="Uploaded Image with Detected Objects" class="responsive-image"> +</div> +<ul> + {% for obj in detected_objects %} + <li>{{ obj.class_name }}: [{{ obj.ymin }}, {{ obj.xmin }}, {{ obj.ymax }}, {{ obj.xmax }}]</li> + {% endfor %} +</ul> +{% endblock %} + +<style> + .image-container { + text-align: center; + } + + .responsive-image { + max-width: 100%; + height: auto; + } +</style> \ No newline at end of file diff --git a/MisplaceAI/item_detector/tests.py b/MisplaceAI/item_detector/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/MisplaceAI/item_detector/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/MisplaceAI/item_detector/urls.py b/MisplaceAI/item_detector/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..fa4f4b8b4e475cf7a58dab6dd6e78d74b51d7b08 --- /dev/null +++ b/MisplaceAI/item_detector/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from .views import detect_items + +app_name = 'item_detector' + +urlpatterns = [ + path('detect/<int:image_id>/', detect_items, name='detect_items'), +] diff --git a/MisplaceAI/item_detector/utils.py b/MisplaceAI/item_detector/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..98bd2503e1dbbb5cb577c83e27a7c288ce906f8b --- /dev/null +++ b/MisplaceAI/item_detector/utils.py @@ -0,0 +1,84 @@ +import numpy as np +from PIL import Image, ImageDraw, ImageFont +from io import BytesIO +import tensorflow as tf +import os + + +from object_detection.utils import label_map_util, ops as utils_ops + +os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" + +MAX_DIMENSION = 1024 + +def load_image_into_numpy_array(path): + img_data = tf.io.gfile.GFile(path, "rb").read() + image = Image.open(BytesIO(img_data)) + (im_width, im_height) = image.size + return np.array(image.getdata()).reshape((im_height, im_width, 3)).astype(np.uint8) + +def load_model(model_path): + return tf.saved_model.load(model_path) + +def create_category_index_from_labelmap(label_map_path, use_display_name=True): + return label_map_util.create_category_index_from_labelmap(label_map_path, use_display_name) + +def resize_image(image): + width, height = image.size + if width > MAX_DIMENSION or height > MAX_DIMENSION: + if width > height: + new_width = MAX_DIMENSION + new_height = int((MAX_DIMENSION / width) * height) + else: + new_height = MAX_DIMENSION + new_width = int((MAX_DIMENSION / height) * width) + return image.resize((new_width, new_height), Image.ANTIALIAS) + return image + +def run_inference(model, category_index, image_path): + image_np = load_image_into_numpy_array(image_path) + input_tensor = tf.convert_to_tensor(image_np) + input_tensor = input_tensor[tf.newaxis, ...] + output_dict = model(input_tensor) + num_detections = int(output_dict.pop("num_detections")) + output_dict = {key: value[0, :num_detections].numpy() for key, value in output_dict.items()} + output_dict["num_detections"] = num_detections + output_dict["detection_classes"] = output_dict["detection_classes"].astype(np.int64) + + detected_objects = [] + for i in range(num_detections): + if output_dict['detection_scores'][i] > 0.5: + ymin, xmin, ymax, xmax = output_dict['detection_boxes'][i] + class_id = output_dict['detection_classes'][i] + class_name = category_index[class_id]['name'] if class_id in category_index else 'N/A' + detected_objects.append({ + 'class_name': class_name, + 'ymin': ymin, + 'xmin': xmin, + 'ymax': ymax, + 'xmax': xmax + }) + + return detected_objects + +def visualize_boxes(image_path, detected_objects, output_path): + image = Image.open(image_path) + image = resize_image(image) # Resize the image if necessary + draw = ImageDraw.Draw(image) + font = ImageFont.load_default() + + for obj in detected_objects: + ymin = obj['ymin'] * image.height + xmin = obj['xmin'] * image.width + ymax = obj['ymax'] * image.height + xmax = obj['xmax'] * image.width + + draw.rectangle([(xmin, ymin), (xmax, ymax)], outline="red", width=3) + draw.text((xmin, ymin), obj['class_name'], fill="red", font=font) + + image.save(output_path) + +def run_inference_and_visualize(model, category_index, image_path, output_path): + detected_objects = run_inference(model, category_index, image_path) + visualize_boxes(image_path, detected_objects, output_path) + return detected_objects diff --git a/MisplaceAI/item_detector/views.py b/MisplaceAI/item_detector/views.py new file mode 100644 index 0000000000000000000000000000000000000000..e9653c4c6e82f6a880083a6e1dac751374670a72 --- /dev/null +++ b/MisplaceAI/item_detector/views.py @@ -0,0 +1,30 @@ +from django.shortcuts import render, get_object_or_404 +from .models import DetectedObject +from process_misplaced_manager.models import UploadedImage +from .utils import run_inference, load_model, create_category_index_from_labelmap, run_inference_and_visualize +import os + +MODEL_PATH = "models/research/object_detection/faster_rcnn_resnet50_v1_1024x1024_coco17_tpu-8/saved_model" +LABEL_MAP_PATH = "models/research/object_detection/data/mscoco_label_map.pbtxt" + +detection_model = load_model(MODEL_PATH) +category_index = create_category_index_from_labelmap(LABEL_MAP_PATH) + +def detect_items(request, image_id): + image = get_object_or_404(UploadedImage, id=image_id) + image_path = image.image.path + output_image_name = "detected_" + os.path.basename(image_path) + output_image_path = os.path.join("media", output_image_name) + detected_objects = run_inference_and_visualize(detection_model, category_index, image_path, output_image_path) + + for obj in detected_objects: + DetectedObject.objects.create( + class_name=obj['class_name'], + ymin=obj['ymin'], + xmin=obj['xmin'], + ymax=obj['ymax'], + xmax=obj['xmax'], + image=image + ) + + return render(request, 'item_detector/results.html', {'detected_objects': detected_objects, 'image': image, 'output_image_url': "/media/" + output_image_name}) diff --git a/MisplaceAI/media/detected_1265_SqbKUM7.jpg b/MisplaceAI/media/detected_1265_SqbKUM7.jpg new file mode 100644 index 0000000000000000000000000000000000000000..08a8b6febef360e4d82675ebe8643dbf1085c38b Binary files /dev/null and b/MisplaceAI/media/detected_1265_SqbKUM7.jpg differ diff --git a/MisplaceAI/media/detected_1265_Ut88mRj.jpg b/MisplaceAI/media/detected_1265_Ut88mRj.jpg new file mode 100644 index 0000000000000000000000000000000000000000..08a8b6febef360e4d82675ebe8643dbf1085c38b Binary files /dev/null and b/MisplaceAI/media/detected_1265_Ut88mRj.jpg differ diff --git a/MisplaceAI/media/detected_1265_qlFQMla.jpg b/MisplaceAI/media/detected_1265_qlFQMla.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ba2a60116c41303b7907c1d222b81881fffd58ad Binary files /dev/null and b/MisplaceAI/media/detected_1265_qlFQMla.jpg differ diff --git a/MisplaceAI/media/uploads/1265.jpg b/MisplaceAI/media/uploads/1265.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cfbe598652ec99461c5dbf29ceb3fdc3de194d15 Binary files /dev/null and b/MisplaceAI/media/uploads/1265.jpg differ diff --git a/MisplaceAI/media/uploads/1265_5PkHAAR.jpg b/MisplaceAI/media/uploads/1265_5PkHAAR.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cfbe598652ec99461c5dbf29ceb3fdc3de194d15 Binary files /dev/null and b/MisplaceAI/media/uploads/1265_5PkHAAR.jpg differ diff --git a/MisplaceAI/media/uploads/1265_CAwc2WF.jpg b/MisplaceAI/media/uploads/1265_CAwc2WF.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cfbe598652ec99461c5dbf29ceb3fdc3de194d15 Binary files /dev/null and b/MisplaceAI/media/uploads/1265_CAwc2WF.jpg differ diff --git a/MisplaceAI/media/uploads/1265_SqbKUM7.jpg b/MisplaceAI/media/uploads/1265_SqbKUM7.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cfbe598652ec99461c5dbf29ceb3fdc3de194d15 Binary files /dev/null and b/MisplaceAI/media/uploads/1265_SqbKUM7.jpg differ diff --git a/MisplaceAI/media/uploads/1265_Ut88mRj.jpg b/MisplaceAI/media/uploads/1265_Ut88mRj.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cfbe598652ec99461c5dbf29ceb3fdc3de194d15 Binary files /dev/null and b/MisplaceAI/media/uploads/1265_Ut88mRj.jpg differ diff --git a/MisplaceAI/media/uploads/1265_htc3TW1.jpg b/MisplaceAI/media/uploads/1265_htc3TW1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cfbe598652ec99461c5dbf29ceb3fdc3de194d15 Binary files /dev/null and b/MisplaceAI/media/uploads/1265_htc3TW1.jpg differ diff --git a/MisplaceAI/media/uploads/1265_qlFQMla.jpg b/MisplaceAI/media/uploads/1265_qlFQMla.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cfbe598652ec99461c5dbf29ceb3fdc3de194d15 Binary files /dev/null and b/MisplaceAI/media/uploads/1265_qlFQMla.jpg differ diff --git a/MisplaceAI/media/uploads/1265_vaU7bAC.jpg b/MisplaceAI/media/uploads/1265_vaU7bAC.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cfbe598652ec99461c5dbf29ceb3fdc3de194d15 Binary files /dev/null and b/MisplaceAI/media/uploads/1265_vaU7bAC.jpg differ diff --git a/MisplaceAI/media/uploads/download.png b/MisplaceAI/media/uploads/download.png new file mode 100644 index 0000000000000000000000000000000000000000..7494af61e1cfb51e8825af72c07b164f377e2a7f Binary files /dev/null and b/MisplaceAI/media/uploads/download.png differ diff --git a/MisplaceAI/media/uploads/download_uzsTYmc.png b/MisplaceAI/media/uploads/download_uzsTYmc.png new file mode 100644 index 0000000000000000000000000000000000000000..7494af61e1cfb51e8825af72c07b164f377e2a7f Binary files /dev/null and b/MisplaceAI/media/uploads/download_uzsTYmc.png differ diff --git a/MisplaceAI/media/uploads/imageedit_1_7276535462.jpg b/MisplaceAI/media/uploads/imageedit_1_7276535462.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a99320e269270fe4dfba128c1598beb721ea1ad3 Binary files /dev/null and b/MisplaceAI/media/uploads/imageedit_1_7276535462.jpg differ diff --git a/MisplaceAI/media/uploads/logoNB.png b/MisplaceAI/media/uploads/logoNB.png new file mode 100644 index 0000000000000000000000000000000000000000..682f1a7d46d887273abea70367053172525b1242 Binary files /dev/null and b/MisplaceAI/media/uploads/logoNB.png differ diff --git a/MisplaceAI/models b/MisplaceAI/models new file mode 160000 index 0000000000000000000000000000000000000000..407e191020295512f7c892910a5de967adb22482 --- /dev/null +++ b/MisplaceAI/models @@ -0,0 +1 @@ +Subproject commit 407e191020295512f7c892910a5de967adb22482 diff --git a/MisplaceAI/placement_rules/__init__.py b/MisplaceAI/placement_rules/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/MisplaceAI/placement_rules/admin.py b/MisplaceAI/placement_rules/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/MisplaceAI/placement_rules/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/MisplaceAI/placement_rules/apps.py b/MisplaceAI/placement_rules/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..eb135fda56dfe177cf9f6dcfc6bc017c97de12c9 --- /dev/null +++ b/MisplaceAI/placement_rules/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + +class PlacementRulesConfig(AppConfig): + name = 'placement_rules' + verbose_name = 'Placement Rules' diff --git a/MisplaceAI/placement_rules/models.py b/MisplaceAI/placement_rules/models.py new file mode 100644 index 0000000000000000000000000000000000000000..71a836239075aa6e6e4ecb700e9c42c95c022d91 --- /dev/null +++ b/MisplaceAI/placement_rules/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/MisplaceAI/placement_rules/tests.py b/MisplaceAI/placement_rules/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/MisplaceAI/placement_rules/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/MisplaceAI/placement_rules/views.py b/MisplaceAI/placement_rules/views.py new file mode 100644 index 0000000000000000000000000000000000000000..91ea44a218fbd2f408430959283f0419c921093e --- /dev/null +++ b/MisplaceAI/placement_rules/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/MisplaceAI/process_misplaced_manager/__init__.py b/MisplaceAI/process_misplaced_manager/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/MisplaceAI/process_misplaced_manager/admin.py b/MisplaceAI/process_misplaced_manager/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/MisplaceAI/process_misplaced_manager/apps.py b/MisplaceAI/process_misplaced_manager/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..cdbd5d7f90fb02dd432a998213e613cb7a319e56 --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/apps.py @@ -0,0 +1,7 @@ +# process_misplaced_manager/apps.py + +from django.apps import AppConfig + +class ProcessMisplacedManagerConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'process_misplaced_manager' diff --git a/MisplaceAI/process_misplaced_manager/forms.py b/MisplaceAI/process_misplaced_manager/forms.py new file mode 100644 index 0000000000000000000000000000000000000000..94c8d440219eedcc65fbd5c9a3e77b1e9a74a5fd --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/forms.py @@ -0,0 +1,6 @@ +# forms.py in process_misplaced_manager + +from django import forms + +class ImageUploadForm(forms.Form): + image = forms.ImageField(label='Select an image to upload') diff --git a/MisplaceAI/process_misplaced_manager/models.py b/MisplaceAI/process_misplaced_manager/models.py new file mode 100644 index 0000000000000000000000000000000000000000..af3dc0b53bd21b2945076bc0adbda3943a028552 --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/models.py @@ -0,0 +1,4 @@ +from django.db import models + +class UploadedImage(models.Model): + image = models.ImageField(upload_to='uploads/') diff --git a/MisplaceAI/process_misplaced_manager/templates/process_misplaced_manager/display_image.html b/MisplaceAI/process_misplaced_manager/templates/process_misplaced_manager/display_image.html new file mode 100644 index 0000000000000000000000000000000000000000..336861e5d870fe9807bb4d2cf59e625ce258a9e4 --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/templates/process_misplaced_manager/display_image.html @@ -0,0 +1,12 @@ +<!-- display_image.html in process_misplaced_manager/templates/process_misplaced_manager --> + +{% extends 'core/base.html' %} + +{% block content %} +<h2>Uploaded Image</h2> +{% if image %} +<img src="{{ image.image.url }}" alt="Uploaded Image"> +{% else %} +<p>No image found.</p> +{% endif %} +{% endblock %} \ No newline at end of file diff --git a/MisplaceAI/process_misplaced_manager/templates/process_misplaced_manager/upload_image.html b/MisplaceAI/process_misplaced_manager/templates/process_misplaced_manager/upload_image.html new file mode 100644 index 0000000000000000000000000000000000000000..9d51f87bd1a349cccf15f7a311cbafc4b850de97 --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/templates/process_misplaced_manager/upload_image.html @@ -0,0 +1,12 @@ +<!-- upload_image.html in process_misplaced_manager/templates/process_misplaced_manager --> + +{% extends 'core/base.html' %} + +{% block content %} +<h2>Upload an Image</h2> +<form method="post" enctype="multipart/form-data"> + {% csrf_token %} + {{ form.as_p }} + <button type="submit">Upload</button> +</form> +{% endblock %} \ No newline at end of file diff --git a/MisplaceAI/process_misplaced_manager/tests.py b/MisplaceAI/process_misplaced_manager/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/MisplaceAI/process_misplaced_manager/urls.py b/MisplaceAI/process_misplaced_manager/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..751d9ff97187677467ee5f3928877710dc8f984a --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/urls.py @@ -0,0 +1,11 @@ +# process_misplaced_manager/urls.py + +from django.urls import path +from .views import upload_image, display_image + +app_name = 'process_misplaced_manager' + +urlpatterns = [ + path('upload-image/', upload_image, name='upload_image'), + path('display-image/<int:image_id>/', display_image, name='display_image'), +] diff --git a/MisplaceAI/process_misplaced_manager/views.py b/MisplaceAI/process_misplaced_manager/views.py new file mode 100644 index 0000000000000000000000000000000000000000..d3dbecc0a13029fbd61d1fec8890f8fe7991f185 --- /dev/null +++ b/MisplaceAI/process_misplaced_manager/views.py @@ -0,0 +1,22 @@ +# process_misplaced_manager/views.py + +from django.shortcuts import render, redirect, get_object_or_404 +from .forms import ImageUploadForm +from .models import UploadedImage + + + +def display_image(request, image_id): + image = get_object_or_404(UploadedImage, id=image_id) + return render(request, 'process_misplaced_manager/display_image.html', {'image': image}) + +def upload_image(request): + if request.method == 'POST': + form = ImageUploadForm(request.POST, request.FILES) + if form.is_valid(): + new_image = UploadedImage(image=request.FILES['image']) + new_image.save() + return redirect('item_detector:detect_items', image_id=new_image.id) + else: + form = ImageUploadForm() + return render(request, 'process_misplaced_manager/upload_image.html', {'form': form}) diff --git a/MisplaceAI/requirements.txt b/MisplaceAI/requirements.txt index cc29688aa50c8efb5cf6da2c59df7104700b3bc6..31213703a506abf04d62cbc016d526abf896dee2 100644 --- a/MisplaceAI/requirements.txt +++ b/MisplaceAI/requirements.txt @@ -1,50 +1,5 @@ -# # TensorFlow and essential machine learning libraries -# tensorflow==2.10.1 -# tensorflow-addons==0.22.0 -# tensorflow-datasets==4.9.0 -# tensorflow-estimator==2.10.0 -# tensorflow-hub==0.16.1 -# tensorflow-io==0.31.0 -# tensorflow-io-gcs-filesystem==0.31.0 -# tensorflow-metadata==1.13.0 -# tensorflow-model-optimization==0.8.0 -# tensorflow-object-detection-api==0.1.1 -# tensorflow-text==2.10.0 - -# # Other essential libraries -# numpy==1.24.4 -# pandas==2.2.0 -# scikit-learn==1.4.1.post1 -# scipy==1.12.0 -# matplotlib==3.8.3 -# seaborn==0.12.2 -# pillow==10.2.0 -# opencv-python==4.9.0.80 -# h5py==3.10.0 -# protobuf==3.19.6 - -# # Additional useful libraries -# absl-py==1.4.0 -# six==1.16.0 -# wrapt==1.16.0 -# termcolor==2.4.0 -# tqdm==4.66.2 -# requests==2.31.0 - -# # Flask for web applications -# flask==2.2.5 - -# # PyYAML for configuration files -# pyyaml==6.0 - -# # Essential Python utilities -# ipython==8.15.0 -# setuptools==68.2.2 -# wheel==0.41.2 - -## Django==3.2 mysqlclient==2.1.0 - - - +Pillow==9.3.0 +tensorflow +opencv-python==4.5.5.64 \ No newline at end of file diff --git a/MisplaceAI/results_viewer/__init__.py b/MisplaceAI/results_viewer/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/MisplaceAI/results_viewer/admin.py b/MisplaceAI/results_viewer/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/MisplaceAI/results_viewer/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/MisplaceAI/results_viewer/apps.py b/MisplaceAI/results_viewer/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..288ce625805d1a19e49a70316611db3eedfc6602 --- /dev/null +++ b/MisplaceAI/results_viewer/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + +class ResultsViewerConfig(AppConfig): + name = 'results_viewer' + verbose_name = 'Results Viewer' diff --git a/MisplaceAI/results_viewer/models.py b/MisplaceAI/results_viewer/models.py new file mode 100644 index 0000000000000000000000000000000000000000..71a836239075aa6e6e4ecb700e9c42c95c022d91 --- /dev/null +++ b/MisplaceAI/results_viewer/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/MisplaceAI/results_viewer/tests.py b/MisplaceAI/results_viewer/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/MisplaceAI/results_viewer/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/MisplaceAI/results_viewer/views.py b/MisplaceAI/results_viewer/views.py new file mode 100644 index 0000000000000000000000000000000000000000..91ea44a218fbd2f408430959283f0419c921093e --- /dev/null +++ b/MisplaceAI/results_viewer/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/MisplaceAI/uploads/download.png b/MisplaceAI/uploads/download.png new file mode 100644 index 0000000000000000000000000000000000000000..7494af61e1cfb51e8825af72c07b164f377e2a7f Binary files /dev/null and b/MisplaceAI/uploads/download.png differ diff --git a/MisplaceAI/uploads/download_1Ob500N.png b/MisplaceAI/uploads/download_1Ob500N.png new file mode 100644 index 0000000000000000000000000000000000000000..7494af61e1cfb51e8825af72c07b164f377e2a7f Binary files /dev/null and b/MisplaceAI/uploads/download_1Ob500N.png differ diff --git a/MisplaceAI/uploads/download_1bAmGpB.png b/MisplaceAI/uploads/download_1bAmGpB.png new file mode 100644 index 0000000000000000000000000000000000000000..7494af61e1cfb51e8825af72c07b164f377e2a7f Binary files /dev/null and b/MisplaceAI/uploads/download_1bAmGpB.png differ diff --git a/MisplaceAI/uploads/download_5FrbmVJ.png b/MisplaceAI/uploads/download_5FrbmVJ.png new file mode 100644 index 0000000000000000000000000000000000000000..7494af61e1cfb51e8825af72c07b164f377e2a7f Binary files /dev/null and b/MisplaceAI/uploads/download_5FrbmVJ.png differ diff --git a/MisplaceAI/uploads/download_HzVXojY.png b/MisplaceAI/uploads/download_HzVXojY.png new file mode 100644 index 0000000000000000000000000000000000000000..7494af61e1cfb51e8825af72c07b164f377e2a7f Binary files /dev/null and b/MisplaceAI/uploads/download_HzVXojY.png differ diff --git a/MisplaceAI/uploads/logoNB_1.png b/MisplaceAI/uploads/logoNB_1.png new file mode 100644 index 0000000000000000000000000000000000000000..682f1a7d46d887273abea70367053172525b1242 Binary files /dev/null and b/MisplaceAI/uploads/logoNB_1.png differ