Skip to content
Snippets Groups Projects
Commit aa43d53a authored by h4-rahman's avatar h4-rahman
Browse files

Moved audio file form into forms.py

parent 83522fce
No related branches found
No related tags found
1 merge request!15Moved audio file form into forms.py
......@@ -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
......@@ -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'
......
# 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)'
})
)
File added
......@@ -18,17 +18,14 @@
<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">
<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)"
>
{{ 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>
......
......@@ -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')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment