diff --git a/myproject/debug.log b/myproject/debug.log index 17a31833391facd425e793bc3730b4ca8a455a2c..5ab8224859533c27919176697cc46b738e026f3c 100644 --- a/myproject/debug.log +++ b/myproject/debug.log @@ -401,3 +401,25 @@ Watching for file changes with StatReloader /usr/src/app/myapp/views.py changed, reloading. Watching for file changes with StatReloader Watching for file changes with StatReloader +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Watching for file changes with StatReloader +/usr/src/app/myapp/forms.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/forms.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/forms.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/forms.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/forms.py changed, reloading. +Watching for file changes with StatReloader diff --git a/myproject/myapp/audio_preprocessing.py b/myproject/myapp/audio_preprocessing.py index 24728a942b3fc959c449a761c96d18efd99fea3c..2e6de553484fb36ec3732fa33a82da7c8f553035 100644 --- a/myproject/myapp/audio_preprocessing.py +++ b/myproject/myapp/audio_preprocessing.py @@ -32,6 +32,17 @@ def preprocess_audio_for_inference(audio_path): audio_path = './static/src/media/Casio Piano C5 1980s.wav' # Update this path preprocessed_data = preprocess_audio_for_inference(audio_path) +# print(f"Number of windows: {len(preprocessed_data)}") +# print(f"Value array: {preprocessed_data[0]}") + +# Write preprocessed data values to a text file +# with open('G53_data.txt', 'w') as file: +# for window in preprocessed_data: +# for value in window.flatten(): +# file.write(str(value) + '\n') +# print("Preprocessed data values written to preprocessed_data.txt") + + # TensorFlow Serving URL url = 'http://localhost:8501/v1/models/instrument_model:predict' diff --git a/myproject/myapp/forms.py b/myproject/myapp/forms.py new file mode 100644 index 0000000000000000000000000000000000000000..a693ce7226a8bf4d18f4e5a830222f296c943e7c --- /dev/null +++ b/myproject/myapp/forms.py @@ -0,0 +1,15 @@ +# forms.py +from django import forms + +class InstrumentDetectionForm(forms.Form): + audio_file = forms.FileField( + label='Select an audio file', + widget=forms.ClearableFileInput(attrs={ + 'class': 'block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400', + 'id': 'audio_file', + 'name': 'audio_file', + 'accept': '.mp3,.wav', + 'onchange': 'loadAudioFile(event)' + }) + ) + diff --git a/myproject/myapp/static/src/media/Casio Piano C5 1980s.wav b/myproject/myapp/static/src/media/Casio Piano C5 1980s.wav new file mode 100644 index 0000000000000000000000000000000000000000..eeaff44f12dd2cfb3f450cf4a80a815443f0b3b3 Binary files /dev/null and b/myproject/myapp/static/src/media/Casio Piano C5 1980s.wav differ diff --git a/myproject/myapp/templates/index1.html b/myproject/myapp/templates/index1.html index 6325f3311057e54e33fe03cbf3986e72b2a84755..c0044f2d18170a5e7eb76ce0fd7fb3c646433677 100644 --- a/myproject/myapp/templates/index1.html +++ b/myproject/myapp/templates/index1.html @@ -18,21 +18,18 @@ <img class="w-240 h-60 rounded-lg" src="{% static 'src/images/0_IPKn3dedq86U4UqP.png' %}" alt="CNN for audio"> </div> </div> - <div class="gap-16 items-center py-8 px-4 mx-auto max-w-screen-xl lg:grid lg:grid-cols-2" > + + <div class="gap-16 items-center py-8 px-4 mx-auto max-w-screen-xl lg:grid lg:grid-cols-2"> <form enctype="multipart/form-data" method="post" id="uploadForm"> {% csrf_token %} - <input - class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400" - id="audio_file" - name="audio_file" - type="file" - accept=".mp3,.wav" - onchange="loadAudioFile(event)" - > - <button type="submit" class="text-white bg-gray-800 hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:border-gray-700"> - Run Algorithm - </button> - </form> + {{ form.audio_file }} + <button type="reset" class="text-gray-800 bg-white hover:bg-gray-100 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-300 dark:hover:bg-gray-400 dark:focus:ring-gray-500 dark:border-gray-500"> + Clear + </button> + <button type="submit" class="text-white bg-gray-800 hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:border-gray-700"> + Run Algorithm + </button> + </form> </div> diff --git a/myproject/myapp/views.py b/myproject/myapp/views.py index 25eaefc36bdb5ee9099e092062b17fa966b6ea4f..afe838746f41c477a1629b9a57f70d611d6cf93a 100644 --- a/myproject/myapp/views.py +++ b/myproject/myapp/views.py @@ -3,6 +3,8 @@ from django.template import RequestContext import logging from django.http import HttpResponse from django.utils import timezone + +from .forms import InstrumentDetectionForm from .models import Log, Action logger = logging.getLogger(__name__) @@ -45,7 +47,8 @@ def index(request): else: return render(request, 'index1.html') else: - return render(request, 'index1.html') + audio_form = InstrumentDetectionForm() + return render(request, 'index1.html', {'form': audio_form}) def users(request): return render(request, 'user_page.html')