Commit 5972248a authored by SupunGurusinghe's avatar SupunGurusinghe

Add new features

parent 70eacf1f
...@@ -61,3 +61,5 @@ Thumbs.db ...@@ -61,3 +61,5 @@ Thumbs.db
*.csv *.csv
*.txt *.txt
venv/
/venv/
import os
from flask import Flask, render_template, request, jsonify from flask import Flask, render_template, request, jsonify
from sinlingua.singlish.rulebased_transliterator import RuleBasedTransliterator
from sinlingua.sinhala_audio.audio_to_text import conversion
app = Flask(__name__) app = Flask(__name__)
...@@ -25,13 +29,22 @@ def index(): ...@@ -25,13 +29,22 @@ def index():
def process(): def process():
input_text = request.form.get('input_text') input_text = request.form.get('input_text')
audio_input = request.files.get('audio_input') audio_input = request.files.get('audio_input')
processed_result = None
if input_text: if input_text:
obj = RuleBasedTransliterator()
# Perform text processing on input_text # Perform text processing on input_text
processed_result = f"{input_text}" # Example text processing out = obj.transliterator(text=input_text)
processed_result = f"{out}" # Example text processing
elif audio_input: elif audio_input:
# Save the uploaded file to a specific directory
upload_dir = 'src'
os.makedirs(upload_dir, exist_ok=True)
audio_path = os.path.join(upload_dir, audio_input.filename)
audio_input.save(audio_path)
# Perform audio processing # Perform audio processing
processed_result = "Audio Collected" out = conversion(path=audio_path)
processed_result = f"{out}"
return jsonify({'processed_result': processed_result}) return jsonify({'processed_result': processed_result})
......
This diff is collapsed.
{
"name": "sinlinguatoolkit",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"electron": "^26.0.0",
"electron-packager": "^17.1.2"
}
}
Flask==2.3.2 Flask==2.3.3
\ No newline at end of file \ No newline at end of file
...@@ -6,67 +6,99 @@ ...@@ -6,67 +6,99 @@
<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>
<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" enctype="multipart/form-data"> <form id="inputForm" enctype="multipart/form-data">
<div class="form-group"> <div class="form-group">
<label for="inputText">Enter Text or Upload Audio:</label> <label for="inputText">Enter Text or Upload Audio:</label>
<textarea class="form-control" id="inputText" name="input_text" rows="5"></textarea> <textarea class="form-control" id="inputText" name="input_text" rows="5"></textarea>
<div class="custom-file"> <div class="custom-file">
<input type="file" accept="audio/*" class="custom-file-input" id="audioInput" name="audio_input"> <input type="file" accept="audio/*" class="custom-file-input" id="audioInput"
<label class="custom-file-label" for="audioInput">Choose File</label> name="audio_input">
</div> <label class="custom-file-label" for="audioInput">Choose File</label>
</div> </div>
<button type="submit" class="btn btn-primary">Process</button> </div>
</form>
</div>
<div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label for="processedResult">Processed Result:</label> <label>Checkboxes:</label>
<textarea class="form-control" id="processedResult" rows="5" readonly></textarea> <div class="form-check">
<input class="form-check-input" type="checkbox" id="checkbox1" name="checkbox1">
<label class="form-check-label" for="checkbox1">Checkbox 1</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="checkbox2" name="checkbox2">
<label class="form-check-label" for="checkbox2">Checkbox 2</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="checkbox3" name="checkbox3">
<label class="form-check-label" for="checkbox3">Checkbox 3</label>
</div>
</div> </div>
<button id="copyButton" class="btn btn-secondary">Copy</button> <button type="submit" class="btn btn-primary">Process</button>
<button type="reset" class="btn btn-secondary">Reset</button>
</form>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="processedResult">Processed Result:</label>
<textarea class="form-control" id="processedResult" rows="5" readonly></textarea>
</div> </div>
<button id="copyButton" class="btn btn-secondary">Copy</button>
</div> </div>
</div> </div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$('#inputForm').submit(function (event) { // Disable checkbox2 if checkbox1 is checked
event.preventDefault(); $('#checkbox1').change(function () {
var inputText = $('#inputText').val(); if ($(this).is(':checked')) {
var audioInput = $('#audioInput')[0].files[0]; // Get the selected audio file $('#checkbox2').prop('disabled', true);
} else {
$('#checkbox2').prop('disabled', false);
}
});
var formData = new FormData(); $('#inputForm').submit(function (event) {
formData.append('input_text', inputText); event.preventDefault();
formData.append('audio_input', audioInput); var inputText = $('#inputText').val();
var audioInput = $('#audioInput')[0].files[0]; // Get the selected audio file
var checkbox1 = $('#checkbox1').is(':checked');
var checkbox2 = $('#checkbox2').is(':checked');
var checkbox3 = $('#checkbox3').is(':checked');
$.ajax({ var formData = new FormData();
type: 'POST', formData.append('input_text', inputText);
url: '/process', formData.append('audio_input', audioInput);
data: formData, formData.append('checkbox1', checkbox1);
contentType: false, formData.append('checkbox2', checkbox2);
processData: false, formData.append('checkbox3', checkbox3);
success: function (response) {
$('#processedResult').val(response.processed_result);
}
});
});
$('#copyButton').click(function () { $.ajax({
var copyText = $('#processedResult'); type: 'POST',
copyText.select(); url: '/process',
document.execCommand('copy'); data: formData,
contentType: false,
processData: false,
success: function (response) {
$('#processedResult').val(response.processed_result);
}
}); });
});
// Display selected file name in the "Choose File" input field $('#copyButton').click(function () {
$('#audioInput').change(function() { var copyText = $('#processedResult');
var fileName = $(this).val().split('\\').pop(); copyText.select();
$(this).siblings('.custom-file-label').addClass('selected').html(fileName); 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>
</html> </html>
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