Api for writing task 2 v1.

This commit is contained in:
Cristiano Ferreira
2023-06-19 23:38:47 +01:00
parent adb07a56ff
commit 48a1197d56
14 changed files with 281 additions and 329 deletions

View File

@@ -1,12 +1,37 @@
import whisper
import os
from pydub import AudioSegment
from functools import reduce
from helper.token_counter import count_tokens
model = whisper.load_model("base")
file_path = "audio-samples/mynameisjeff.wav"
audio_file = AudioSegment.from_file(file_path)
if os.path.exists(file_path):
result = model.transcribe(file_path, fp16=False, language='English', verbose=True)
print(result["text"])
else:
print("File not found:", file_path)
# model = whisper.load_model("base")
# file_path = "audio-samples/mynameisjeff.wav"
# audio_file = AudioSegment.from_file(file_path)
# if os.path.exists(file_path):
# result = model.transcribe(file_path, fp16=False, language='English', verbose=True)
# print(result["text"])
# else:
# print("File not found:", file_path)
messages = [
{
"role": "system",
"content": "You are a IELTS examiner.",
},
{
"role": "system",
"content": f"The question you have to grade is of type and is the following: ",
},
{
"role": "system",
"content": "Please provide a JSON object response with the overall grade and breakdown grades, "
"formatted as follows: {'overall': 7.0, 'task_response': {'Task Achievement': 8.0, "
"'Coherence and Cohesion': 6.5, 'Lexical Resource': 7.5, 'Grammatical Range and Accuracy': "
"6.0}}",
},
{
"role": "user",
"content": f"Evaluate this answer according to ielts grading system:",
},
]
token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'],
map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0)
print(token_count)