Commit ee4d8980 authored by SupunGurusinghe's avatar SupunGurusinghe

Add new features

parent 604e8f67
...@@ -2,6 +2,8 @@ import os ...@@ -2,6 +2,8 @@ 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.singlish.rulebased_transliterator import RuleBasedTransliterator
from sinlingua.grammar_rule.grammar_main import GrammarMain
# from sinlingua.summarizer.faster_longformer import FLongformerTextSummarizer
from sinlingua.sinhala_audio.audio_to_text import conversion from sinlingua.sinhala_audio.audio_to_text import conversion
app = Flask(__name__) app = Flask(__name__)
...@@ -25,18 +27,42 @@ def index(): ...@@ -25,18 +27,42 @@ def index():
return render_template('index.html', processed_result=processed_result) return render_template('index.html', processed_result=processed_result)
@app.route('/singlish', methods=['GET', 'POST'])
def singlish():
return render_template('singlish.html')
@app.route('/grammar', methods=['GET', 'POST'])
def grammar():
return render_template('grammar.html')
@app.route('/summarize', methods=['GET', 'POST'])
def summarize():
return render_template('summarize.html')
@app.route('/process', methods=['POST']) @app.route('/process', methods=['POST'])
def process(): def process():
input_text, audio_input = None, None
checkbox1, checkbox2, checkbox3, checkbox4 = None, None, None, None
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: checkbox1 = request.form.get('checkbox1') == 'true'
checkbox2 = request.form.get('checkbox2') == 'true'
checkbox3 = request.form.get('checkbox3') == 'true'
checkbox4 = request.form.get('checkbox4') == 'true'
print(request.form)
if input_text and checkbox1:
obj = RuleBasedTransliterator() obj = RuleBasedTransliterator()
# Perform text processing on input_text # Perform text processing on input_text
out = obj.transliterator(text=input_text) out = obj.transliterator(text=input_text)
processed_result = f"{out}" # Example text processing processed_result = f"{out}" # Example text processing
elif audio_input: elif audio_input and checkbox2:
# Save the uploaded file to a specific directory # Save the uploaded file to a specific directory
upload_dir = 'src' upload_dir = 'src'
os.makedirs(upload_dir, exist_ok=True) os.makedirs(upload_dir, exist_ok=True)
...@@ -45,6 +71,37 @@ def process(): ...@@ -45,6 +71,37 @@ def process():
# Perform audio processing # Perform audio processing
out = conversion(path=audio_path) out = conversion(path=audio_path)
processed_result = f"{out}" processed_result = f"{out}"
else:
processed_result = input_text
if checkbox3:
obj2 = GrammarMain()
paragraphs = processed_result.split('\n')
processed_paragraphs = []
for paragraph in paragraphs:
# Step 2: Split paragraphs into sentences using periods (.) as delimiter
sentences = paragraph.split('.')
processed_sentences = []
for sentence in sentences:
# Remove leading and trailing whitespaces from the sentence
sentence = sentence.strip()
# Step 3: Process each sentence
processed_sentence = obj2.mapper(sentence)
processed_sentences.append(processed_sentence)
# Step 4: Join processed sentences to form paragraph
processed_paragraph = ' '.join(processed_sentences)
processed_paragraphs.append(processed_paragraph)
# Join processed paragraphs to form final processed text
processed_result = '\n'.join(processed_paragraphs)
# if checkbox4 == "true":
# obj3 = FLongformerTextSummarizer()
# processed_result = obj3.refined_summarize_by_word_count(processed_result)
return jsonify({'processed_result': processed_result}) return jsonify({'processed_result': processed_result})
......
$(document).ready(function () {
// Smooth-scroll to sections when a link is clicked
$('.sidenav a').on('click', function (event) {
event.preventDefault();
var target = $(this).attr('href');
$('html, body').animate({
scrollTop: $(target).offset().top
}, 800);
});
// Toggle the hidden class on the navigation bar
function toggleSideNav(show) {
$('#js-sidenav').toggleClass('sidenav-hidden', !show);
}
var isMouseOverNav = false;
// Show the navigation bar when cursor enters the left side
$(document).on('mousemove', function (event) {
var mouseX = event.clientX;
var mouseY = event.clientY;
var navWidth = $('#js-sidenav').width(); // Width of the navigation bar
if (mouseX <= 60) {
toggleSideNav(true);
isMouseOverNav = true;
} else if (!isMouseOverNav || (mouseX > navWidth && mouseY > navWidth)) {
toggleSideNav(false);
isMouseOverNav = false;
}
});
});
/* styles.css */
/* Common styles */
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
/* Styles for the side navigation bar */
.sidenav {
width: 250px;
background-color: #333;
top: 0;
left: 0;
height: 100%;
padding-top: 20px;
display: flex;
flex-direction: column;
position:fixed;
z-index:1000;
}
/* Styles for side navigation bar links */
.sidenav a {
padding: 10px 15px;
text-decoration: none;
font-size: 18px;
color: #fff;
transition: background-color 0.3s;
}
.sidenav a:hover {
background-color: #555;
}
/* Styles for the content area */
.content {
margin-left: 250px; /* Match the width of the side navigation bar */
padding: 20px;
background-color: #f0f0f0;
}
/* Add this style to your styles.css */
.sidenav-hidden {
transform: translateX(-250px);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="../static/styles.css">
</head>
<body>
<!-- Side Navigation Bar -->
<div class="sidenav">
<a href="index.html">Default Toolkit</a>
<a href="singlish.html">Advance Singlish</a>
<a href="grammar.html">Advance Grammar</a>
<a href="summarize.html">Advance Summarize</a>
<!-- Add more links for other sections or pages -->
</div>
<script src="../static/script.js"></script>
</body>
</html>
\ No newline at end of file
...@@ -4,39 +4,63 @@ ...@@ -4,39 +4,63 @@
<title>Input Page</title> <title>Input Page</title>
<!-- Include Bootstrap CSS --> <!-- Include Bootstrap CSS -->
<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">
<link rel="stylesheet" href="../static/styles.css">
</head> </head>
<body> <body>
<!-- Side Navigation Bar -->
<div class="sidenav" id="js-sidenav">
<a href="{{ url_for('index') }}">Default Toolkit</a>
<a href="{{ url_for('singlish') }}">Advance Singlish</a>
<a href="{{ url_for('grammar') }}">Advance Grammar</a>
<a href="{{ url_for('summarize') }}">Advance Summarize</a>
<!-- Add more links for other sections or pages -->
</div>
<div class="container mt-5"> <div class="container mt-5">
<div class="row">
<div class="col-md-12 text-center mb-4">
<h1>සිංLingua Toolkit</h1>
<hr>
</div>
</div>
<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 mt-1">
<input type="file" accept="audio/*" class="custom-file-input" id="audioInput" <input type="file" accept="audio/*" class="custom-file-input" id="audioInput"
name="audio_input"> name="audio_input">
<label class="custom-file-label" for="audioInput">Choose File</label> <label class="custom-file-label" for="audioInput">Choose File</label>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group mt-1">
<label>Checkboxes:</label> <label>Checkboxes:</label>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" id="checkbox1" name="checkbox1"> <input class="form-check-input" type="checkbox" id="checkbox1" name="checkbox1">
<label class="form-check-label" for="checkbox1">Checkbox 1</label> <label class="form-check-label" for="checkbox1">Singlish to Sinhala Text Conversion</label>
</div> </div>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" id="checkbox2" name="checkbox2"> <input class="form-check-input" type="checkbox" id="checkbox2" name="checkbox2">
<label class="form-check-label" for="checkbox2">Checkbox 2</label> <label class="form-check-label" for="checkbox2">Audio to Sinhala Text Conversion</label>
</div> </div>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" id="checkbox3" name="checkbox3"> <input class="form-check-input" type="checkbox" id="checkbox3" name="checkbox3">
<label class="form-check-label" for="checkbox3">Checkbox 3</label> <label class="form-check-label" for="checkbox3">Grammar Rule Mapping</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="checkbox4" name="checkbox4">
<label class="form-check-label" for="checkbox4">Sinhala Text Summarization</label>
</div> </div>
</div> </div>
<button type="submit" class="btn btn-primary">Process</button> <button type="submit" class="btn btn-primary">Process</button>
<button type="reset" class="btn btn-secondary">Reset</button> <button type="reset" class="btn btn-secondary">Reset</button>
</form> </form>
<!-- Error Alert -->
<div class="alert alert-danger mt-3" id="errorAlert" style="display: none;">
<strong>Error:</strong> <span id="errorText"></span>
</div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
...@@ -49,24 +73,61 @@ ...@@ -49,24 +73,61 @@
</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 src="../static/script.js"></script>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
// Disable checkbox2 if checkbox1 is checked // Automatically handle checkbox behavior based on input type
$('#checkbox1').change(function () { $('#inputText').on('input', function () {
if ($(this).is(':checked')) { var inputText = $(this).val();
$('#checkbox2').prop('disabled', true); var audioInput = $('#audioInput')[0].files[0];
if (inputText && !audioInput) {
$('#checkbox2').prop('checked', false).prop('disabled', true);
$('#audioInput').prop('disabled', true);
} else {
$('#checkbox2').prop('checked', true).prop('disabled', false);
$('#audioInput').prop('disabled', false);
}
});
$('#audioInput').change(function () {
var inputText = $('#inputText').val();
var audioInput = $(this)[0].files[0];
if (audioInput) {
$('#checkbox1').prop('checked', false).prop('disabled', true);
$('#inputText').prop('disabled', true);
} else { } else {
$('#checkbox2').prop('disabled', false); $('#checkbox1').prop('disabled', false);
$('#inputText').prop('disabled', false);
} }
}); });
$('#inputForm').submit(function (event) { $('#inputForm').submit(function (event) {
event.preventDefault(); event.preventDefault();
$('#errorAlert').hide(); // Hide error alert on form submission
var inputText = $('#inputText').val(); var inputText = $('#inputText').val();
var audioInput = $('#audioInput')[0].files[0]; // Get the selected audio file var audioInput = $('#audioInput')[0].files[0]; // Get the selected audio file
var checkbox1 = $('#checkbox1').is(':checked'); var checkbox1 = $('#checkbox1').is(':checked');
var checkbox2 = $('#checkbox2').is(':checked'); var checkbox2 = $('#checkbox2').is(':checked');
var checkbox3 = $('#checkbox3').is(':checked'); var checkbox3 = $('#checkbox3').is(':checked');
var checkbox4 = $('#checkbox4').is(':checked');
// Check if either text or audio input is provided
if (!inputText && !audioInput) {
showError("Please provide either text or audio input.");
return;
}
// Check for specific conditions based on checkboxes
if (checkbox2 && !audioInput) {
showError("No audio file inserted for Audio to Sinhala Text Conversion.");
return;
}
if (!checkbox1 && !checkbox2 && !checkbox3 && !checkbox4) {
showError("Please select at least one checkbox.");
return;
}
var formData = new FormData(); var formData = new FormData();
formData.append('input_text', inputText); formData.append('input_text', inputText);
...@@ -74,6 +135,7 @@ ...@@ -74,6 +135,7 @@
formData.append('checkbox1', checkbox1); formData.append('checkbox1', checkbox1);
formData.append('checkbox2', checkbox2); formData.append('checkbox2', checkbox2);
formData.append('checkbox3', checkbox3); formData.append('checkbox3', checkbox3);
formData.append('checkbox4', checkbox4);
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
...@@ -98,6 +160,26 @@ ...@@ -98,6 +160,26 @@
var fileName = $(this).val().split('\\').pop(); var fileName = $(this).val().split('\\').pop();
$(this).siblings('.custom-file-label').addClass('selected').html(fileName); $(this).siblings('.custom-file-label').addClass('selected').html(fileName);
}); });
// Function to show error in the error alert
function showError(message) {
$('#errorText').text(message);
$('#errorAlert').show();
}
// Reset the form when "Reset" button is clicked
$('#inputForm button[type="reset"]').click(function () {
$('#inputForm')[0].reset(); // Reset the form
$('#checkbox2').prop('disabled', false); // Enable checkbox2
$('#checkbox1').prop('disabled', false); // Enable checkbox1
$('#audioInput').prop('disabled', false); // Enable audio input
$('#inputText').prop('disabled', false); // Enable text input
$('#errorAlert').hide(); // Hide error alert
// Reset the audio input field
$('#audioInput').replaceWith($('#audioInput').val('').clone(true));
$('#audioInput').siblings('.custom-file-label').removeClass('selected').html('Choose File');
});
}); });
</script> </script>
</body> </body>
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="../static/styles.css">
</head>
<body>
<!-- Side Navigation Bar -->
<div class="sidenav">
<a href="index.html">Default Toolkit</a>
<a href="singlish.html">Advance Singlish</a>
<a href="grammar.html">Advance Grammar</a>
<a href="summarize.html">Advance Summarize</a>
<!-- Add more links for other sections or pages -->
</div>
<script src="../static/script.js"></script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="../static/styles.css">
</head>
<body>
<!-- Side Navigation Bar -->
<div class="sidenav">
<a href="index.html">Default Toolkit</a>
<a href="singlish.html">Advance Singlish</a>
<a href="grammar.html">Advance Grammar</a>
<a href="summarize.html">Advance Summarize</a>
<!-- Add more links for other sections or pages -->
</div>
<script src="../static/script.js"></script>
</body>
</html>
\ No newline at end of file
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