Commit d38f7faf authored by W.G.G.A. Supun Sameera's avatar W.G.G.A. Supun Sameera

Merge branch 'IT20146924' into 'master'

Added audio feature

See merge request !2
parents dda89a47 70eacf1f
...@@ -9,8 +9,14 @@ def index(): ...@@ -9,8 +9,14 @@ def index():
if request.method == 'POST': if request.method == 'POST':
input_text = request.form.get('input_text') input_text = request.form.get('input_text')
# Perform processing on input_text and set processed_result audio_input = request.files.get('audio_input')
processed_result = f"Processed: {input_text}" # Example processing
if input_text:
# Perform text processing on input_text
processed_result = f"Processed: {input_text}" # Example text processing
elif audio_input:
# Perform audio processing
processed_result = "Audio Collected"
return render_template('index.html', processed_result=processed_result) return render_template('index.html', processed_result=processed_result)
...@@ -18,8 +24,15 @@ def index(): ...@@ -18,8 +24,15 @@ def index():
@app.route('/process', methods=['POST']) @app.route('/process', methods=['POST'])
def process(): def process():
input_text = request.form.get('input_text') input_text = request.form.get('input_text')
# Perform processing on input_text and set processed_result audio_input = request.files.get('audio_input')
processed_result = f"{input_text}" # Example processing
if input_text:
# Perform text processing on input_text
processed_result = f"{input_text}" # Example text processing
elif audio_input:
# Perform audio processing
processed_result = "Audio Collected"
return jsonify({'processed_result': processed_result}) return jsonify({'processed_result': processed_result})
......
...@@ -6,14 +6,17 @@ ...@@ -6,14 +6,17 @@
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head> </head>
<body> <body>
<webview src="http://localhost:5000" style="width: 100%; height: 100%;"></webview>
<div class="container mt-5"> <div class="container mt-5">
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<form id="inputForm"> <form id="inputForm" enctype="multipart/form-data">
<div class="form-group"> <div class="form-group">
<label for="inputText">Enter Text:</label> <label for="inputText">Enter Text or Upload Audio:</label>
<textarea class="form-control" id="inputText" rows="5"></textarea> <textarea class="form-control" id="inputText" name="input_text" rows="5"></textarea>
<div class="custom-file">
<input type="file" accept="audio/*" class="custom-file-input" id="audioInput" name="audio_input">
<label class="custom-file-label" for="audioInput">Choose File</label>
</div>
</div> </div>
<button type="submit" class="btn btn-primary">Process</button> <button type="submit" class="btn btn-primary">Process</button>
</form> </form>
...@@ -34,10 +37,18 @@ ...@@ -34,10 +37,18 @@
$('#inputForm').submit(function (event) { $('#inputForm').submit(function (event) {
event.preventDefault(); event.preventDefault();
var inputText = $('#inputText').val(); var inputText = $('#inputText').val();
var audioInput = $('#audioInput')[0].files[0]; // Get the selected audio file
var formData = new FormData();
formData.append('input_text', inputText);
formData.append('audio_input', audioInput);
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/process', url: '/process',
data: { input_text: inputText }, data: formData,
contentType: false,
processData: false,
success: function (response) { success: function (response) {
$('#processedResult').val(response.processed_result); $('#processedResult').val(response.processed_result);
} }
...@@ -49,6 +60,12 @@ ...@@ -49,6 +60,12 @@
copyText.select(); copyText.select();
document.execCommand('copy'); document.execCommand('copy');
}); });
// Display selected file name in the "Choose File" input field
$('#audioInput').change(function() {
var fileName = $(this).val().split('\\').pop();
$(this).siblings('.custom-file-label').addClass('selected').html(fileName);
});
}); });
</script> </script>
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment