Adding bullet points to grading_summary endpoint

This commit is contained in:
Pedro Fonseca
2024-03-24 23:21:38 +00:00
parent 3aa33f10b4
commit 94c2b5a052
2 changed files with 34 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ nltk.download('words')
from nltk.corpus import words
from helper.constants import *
def speech_to_text(file_path):
if os.path.exists(file_path):
model = whisper.load_model("base")
@@ -17,6 +18,7 @@ def speech_to_text(file_path):
print("File not found:", file_path)
raise Exception("File " + file_path + " not found.")
def text_to_speech(text: str, file_name: str):
# Initialize the Amazon Polly client
client = boto3.client(
@@ -53,6 +55,7 @@ def text_to_speech(text: str, file_name: str):
print("Speech segments saved to " + file_name)
def conversation_text_to_speech(conversation: list, file_name: str):
# Initialize the Amazon Polly client
client = boto3.client(
@@ -66,7 +69,7 @@ def conversation_text_to_speech(conversation: list, file_name: str):
# Iterate through the text segments, convert to audio segments, and store them
for segment in conversation:
response = client.synthesize_speech(
Engine="neural",
Engine="neural",
Text=segment["text"],
OutputFormat="mp3",
VoiceId=segment["voice"]
@@ -89,17 +92,20 @@ def conversation_text_to_speech(conversation: list, file_name: str):
print("Speech segments saved to " + file_name)
def has_words(text: str):
english_words = set(words.words())
words_in_input = text.split()
return any(word.lower() in english_words for word in words_in_input)
def has_x_words(text: str, quantity):
english_words = set(words.words())
words_in_input = text.split()
english_word_count = sum(1 for word in words_in_input if word.lower() in english_words)
return english_word_count >= quantity
def divide_text(text, max_length=3000):
if len(text) <= max_length:
return [text]
@@ -119,4 +125,4 @@ def divide_text(text, max_length=3000):
divisions.append(text[current_position:next_position])
current_position = next_position
return divisions
return divisions