diff --git a/backend/api/__init__.py b/backend/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/admin.py b/backend/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/backend/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/backend/api/apps.py b/backend/api/apps.py new file mode 100644 index 0000000..66656fd --- /dev/null +++ b/backend/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/backend/api/forms.py b/backend/api/forms.py new file mode 100644 index 0000000..3606870 --- /dev/null +++ b/backend/api/forms.py @@ -0,0 +1,12 @@ +from django import forms + +class UploadFileForm(forms.Form): + file = forms.FileField(label='Select a file') + + # You can add custom validation if needed + def clean_file(self): + file = self.cleaned_data.get('file') + if not file: + raise forms.ValidationError("No file uploaded!") + # Additional custom validations can be added here + return file diff --git a/backend/api/migrations/__init__.py b/backend/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api/models.py b/backend/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/backend/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/backend/api/tasks.py b/backend/api/tasks.py new file mode 100644 index 0000000..71afd05 --- /dev/null +++ b/backend/api/tasks.py @@ -0,0 +1,11 @@ +from __future__ import absolute_import, unicode_literals +from celery import shared_task +from src.input.file_reader import read_audio #export PYTHONPATH="/home/karthikeyan/code/MainProject/freq-split-enhance:$PYTHONPATH" for exporting the module + +import time + +@shared_task +def process_uploaded_file(file_path): + # Simulate long-running task + read_audio(file_path=file_path) + return 'File processed' diff --git a/backend/api/tests.py b/backend/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/backend/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/api/views.py b/backend/api/views.py new file mode 100644 index 0000000..1753789 --- /dev/null +++ b/backend/api/views.py @@ -0,0 +1,31 @@ +from django.shortcuts import render +from django.http import JsonResponse +from .tasks import process_uploaded_file +from .forms import UploadFileForm +import os + +# Create your views here. +def handle_uploaded_file(f, file_path): + with open(file_path, 'wb+') as destination: + for chunk in f.chunks(): + destination.write(chunk) + +def upload(request): + if request.method == 'POST': + form = UploadFileForm(request.POST, request.FILES) + if form.is_valid(): + file = form.cleaned_data['file'] + file_path = os.path.join('uploads', file.name) # Change 'uploads' to your desired directory + handle_uploaded_file(file, file_path) + task = process_uploaded_file.delay(file_path) + return JsonResponse({'task_id': task.id}) + + else: + form = UploadFileForm() + return render(request, 'upload.html', {'form': form}) + +from celery.result import AsyncResult + +def check_task_status(request, task_id): + task_result = AsyncResult(task_id) + return JsonResponse({'status': task_result.status, 'result': task_result.result}) diff --git a/backend/backend/__init__.py b/backend/backend/__init__.py new file mode 100644 index 0000000..52ffd13 --- /dev/null +++ b/backend/backend/__init__.py @@ -0,0 +1 @@ +from celery_app import app as celery diff --git a/backend/backend/asgi.py b/backend/backend/asgi.py new file mode 100644 index 0000000..ed01e6a --- /dev/null +++ b/backend/backend/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for backend 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/5.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') + +application = get_asgi_application() diff --git a/backend/backend/settings.py b/backend/backend/settings.py new file mode 100644 index 0000000..f152247 --- /dev/null +++ b/backend/backend/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for backend project. + +Generated by 'django-admin startproject' using Django 5.1.4. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.1/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/5.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-qkh9wpte((ik5#r(l+mj@5rkiy!2-4^&b%0q@7yehgc+i0t20d' + +# 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', + 'api' +] + +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 = 'backend.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 = 'backend.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.1/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/5.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.1/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +CELERY_BROKER_URL = 'redis://localhost:6379/0' +CELERY_ACCEPT_CONTENT = ['json'] +CELERY_TASK_SERIALIZER = 'json' diff --git a/backend/backend/urls.py b/backend/backend/urls.py new file mode 100644 index 0000000..08bda50 --- /dev/null +++ b/backend/backend/urls.py @@ -0,0 +1,24 @@ +""" +URL configuration for backend project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.1/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 +from api.views import upload + +urlpatterns = [ + path('admin/', admin.site.urls), + path('upload/',upload) +] diff --git a/backend/backend/wsgi.py b/backend/backend/wsgi.py new file mode 100644 index 0000000..07bda9d --- /dev/null +++ b/backend/backend/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for backend 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/5.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') + +application = get_wsgi_application() diff --git a/backend/celery_app.py b/backend/celery_app.py new file mode 100644 index 0000000..12ffede --- /dev/null +++ b/backend/celery_app.py @@ -0,0 +1,9 @@ +from celery import Celery + +app = Celery('backend') + +# Load configuration from Django settings, using the CELERY namespace. +app.config_from_object('django.conf:settings', namespace='CELERY') + +# Autodiscover tasks from installed apps. +app.autodiscover_tasks() diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 new file mode 100644 index 0000000..a594b9d Binary files /dev/null and b/backend/db.sqlite3 differ diff --git a/backend/manage.py b/backend/manage.py new file mode 100755 index 0000000..eb6431e --- /dev/null +++ b/backend/manage.py @@ -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', 'backend.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() diff --git a/requirements.txt b/requirements.txt index 470e19c..97e2a49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,25 @@ absl-py==2.1.0 +amqp==5.3.1 antlr4-python3-runtime==4.9.3 +asgiref==3.8.1 asttokens==3.0.0 astunparse==1.6.3 audioread==3.0.1 +billiard==4.2.1 +celery==5.4.0 certifi==2024.12.14 cffi==1.17.1 charset-normalizer==3.4.0 +click==8.1.8 +click-didyoumean==0.3.1 +click-plugins==1.1.1 +click-repl==0.3.0 cloudpickle==3.1.0 contourpy==1.3.1 cycler==0.12.1 decorator==5.1.1 demucs==4.0.1 +Django==5.1.4 dora_search==0.1.12 einops==0.8.0 executing==2.1.0 @@ -30,6 +39,7 @@ joblib==1.4.2 julius==0.2.7 keras==3.7.0 kiwisolver==1.4.8 +kombu==5.4.2 lameenc==1.7.0 lazy_loader==0.4 libclang==18.1.1 @@ -84,6 +94,7 @@ PyQt6_sip==13.9.1 pytest==8.3.4 python-dateutil==2.9.0.post0 PyYAML==6.0.2 +redis==5.2.1 requests==2.32.3 retrying==1.3.4 rich==13.9.4 @@ -93,6 +104,7 @@ setuptools==75.6.0 six==1.17.0 soundfile==0.12.1 soxr==0.5.0.post1 +sqlparse==0.5.3 stack-data==0.6.3 submitit==1.5.2 sympy==1.13.1 @@ -110,7 +122,9 @@ traitlets==5.14.3 treetable==0.2.5 triton==3.1.0 typing_extensions==4.12.2 +tzdata==2024.2 urllib3==2.3.0 +vine==5.1.0 wcwidth==0.2.13 Werkzeug==3.1.3 wheel==0.45.1