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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import whisper
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import pytube
|
| 7 |
+
from moviepy.editor import VideoFileClip
|
| 8 |
+
import moviepy.editor as movpy
|
| 9 |
+
from moviepy.editor import AudioFileClip
|
| 10 |
+
from pydub import AudioSegment
|
| 11 |
+
from pytube import YouTube
|
| 12 |
+
import gradio as gr
|
| 13 |
+
import collections
|
| 14 |
+
from gtts import gTTS
|
| 15 |
+
|
| 16 |
+
##############################################################################
|
| 17 |
+
openai.api_key = "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"
|
| 18 |
+
#create gradio app
|
| 19 |
+
class NamedBytesIO(BytesIO):
|
| 20 |
+
def __init__(self, *args, **kwargs):
|
| 21 |
+
self._name = kwargs.pop('name', 'unnamed.mp3')
|
| 22 |
+
super(NamedBytesIO, self).__init__(*args, **kwargs)
|
| 23 |
+
|
| 24 |
+
@property
|
| 25 |
+
def name(self):
|
| 26 |
+
return self._name
|
| 27 |
+
|
| 28 |
+
##############################################################################
|
| 29 |
+
def transcribe_audio(audio_file_path):
|
| 30 |
+
model_id = 'whisper-1'
|
| 31 |
+
|
| 32 |
+
# audio_file_path = "C:\VOLUNTEER\TOASTMASTER\Tell me about yourself - bad graduate job interview answer tell me about yourselfout.mp3"
|
| 33 |
+
audio_file_path = audio_file_path
|
| 34 |
+
audio = AudioSegment.from_file(audio_file_path, format="mp3")
|
| 35 |
+
|
| 36 |
+
audio_duration = int(audio.duration_seconds)
|
| 37 |
+
|
| 38 |
+
print(f"Duration of the audio is {audio_duration} seconds")
|
| 39 |
+
chunk_duration = 60 * 1000 * 20 # 20 minute in milliseconds
|
| 40 |
+
|
| 41 |
+
transcriptions = []
|
| 42 |
+
|
| 43 |
+
for i in range(0, audio_duration, chunk_duration):
|
| 44 |
+
chunk = audio[i:i + chunk_duration]
|
| 45 |
+
chunk_buffer = NamedBytesIO(name='chunk.mp3')
|
| 46 |
+
chunk.export(chunk_buffer, format="mp3")
|
| 47 |
+
chunk_buffer.seek(0)
|
| 48 |
+
|
| 49 |
+
response = openai.Audio.transcribe(
|
| 50 |
+
api_key=openai.api_key,
|
| 51 |
+
model=model_id,
|
| 52 |
+
file=chunk_buffer,
|
| 53 |
+
prompt="""
|
| 54 |
+
Dont remove any filler words in transcribe. eg: um, umm, uh, ah, er, mhm, hmm, mm, mmm, oh, ohh, let me think like, Okay, ok, here's what I'm, like, thinking, you know, well, so, actually, basically, literally, right, i mean,anyway...
|
| 55 |
+
This is human voices with various tone and accents.
|
| 56 |
+
1) Transcibe every words and all signals, dont skip any
|
| 57 |
+
2) Dont correct the grammar
|
| 58 |
+
3) Dont correct the spelling
|
| 59 |
+
4) Dont remove any redundant words or punctuations
|
| 60 |
+
5) if there is a pause in the audio, please add a comma(,) in the transcribe
|
| 61 |
+
6) if there is a long pause in the audio, please add a period(.) in the transcribe
|
| 62 |
+
"""
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
transcriptions.append(response['text'])
|
| 66 |
+
|
| 67 |
+
final_transcription = ' '.join(transcriptions)
|
| 68 |
+
|
| 69 |
+
print(final_transcription.replace('.', '.\n'))
|
| 70 |
+
|
| 71 |
+
return final_transcription
|
| 72 |
+
#########################################################################################
|
| 73 |
+
|
| 74 |
+
def get_feedback(audio_file_path):
|
| 75 |
+
|
| 76 |
+
transcribed_text = transcribe_audio(audio_file_path)
|
| 77 |
+
# response = final_transcription
|
| 78 |
+
|
| 79 |
+
prompt = f"""
|
| 80 |
+
Pretend that you are an interview coach with 25 years of experience.
|
| 81 |
+
Evaluate the following response based on the evaluation criteria:
|
| 82 |
+
# please provide feedback on the following response based on the evaluation criteria:
|
| 83 |
+
# language, tone & personality, and a 5-point system for clarity, vocal variety, comfort level, interest, and well-supported content.
|
| 84 |
+
|
| 85 |
+
Evaluation criteria:
|
| 86 |
+
A) Language:
|
| 87 |
+
1. use of Filler words: count the filler words and list them: eg: um, umm, uh, ah, er, mhm, hmm, mm, mmm, oh, ohh, let me think like, Okay, ok, here's what I'm, like, thinking, you know, well, so, actually, basically, literally, right, i mean,anyway...
|
| 88 |
+
example: um: 3, yeah: 2
|
| 89 |
+
2. use of redundant words: list them: example: sum total, joint collaboration, unexpected surprise, future plans, new record...etc
|
| 90 |
+
example: sum total: 2, joint collaboration: 1
|
| 91 |
+
3. use of jargons: list them
|
| 92 |
+
|
| 93 |
+
B) Tone & personality:
|
| 94 |
+
1. Tone: What is the Tone?
|
| 95 |
+
A. Positive/optimistic: Expressing a hopeful or upbeat outlook, such as excitement, joy, or satisfaction. Example: "I'm really looking forward to this vacation!"
|
| 96 |
+
B. Negative/pessimistic: Expressing a negative or gloomy outlook, such as sadness, frustration, or disappointment. Example: "I don't think I can handle any more bad news."
|
| 97 |
+
C. Neutral/objective: Expressing an unbiased or factual outlook, without any emotion or bias. Example: "The temperature is 75 degrees and the sky is clear."
|
| 98 |
+
D. Sarcastic: Expressing a tone of mockery or irony, often with the opposite meaning of what is being said. Example: "Oh great, another Monday morning. Just what I needed."
|
| 99 |
+
E. Formal/polite: Using formal language and expressions to show respect and politeness. Example: "I would be most grateful if you could provide me with further information."
|
| 100 |
+
F. Informal/casual: Using casual language and expressions to show familiarity and informality. Example: "Hey, what's up? Wanna hang out later?"
|
| 101 |
+
G. Authoritative: Expressing a tone of authority or control, such as in instructions or commands. Example: "You need to follow these procedures precisely to ensure safety."
|
| 102 |
+
H. Condescending: Expressing a tone of superiority or patronization towards others.
|
| 103 |
+
2. Personality traits: Insights into the personality traits?
|
| 104 |
+
A. Extraversion: Extraverted individuals tend to be outgoing, sociable, and talkative.
|
| 105 |
+
B. Introversion: Introverted individuals tend to be more reserved, reflective, and introspective.
|
| 106 |
+
C. Conscientiousness: Conscientious individuals tend to be organized, responsible, and diligent.
|
| 107 |
+
D. Agreeableness: Agreeable individuals tend to be friendly, cooperative, and empathetic.
|
| 108 |
+
E. Neuroticism: Neurotic individuals tend to be anxious, sensitive, and easily stressed.
|
| 109 |
+
3. Relevance: Does the response address the question asked and provide relevant information?
|
| 110 |
+
4. Clarity: Is the response clear and concise?
|
| 111 |
+
5. Specificity / examples or details: Does the response provide specific examples or details that demonstrate the interviewee's skills, experiences, or qualifications?
|
| 112 |
+
6. Confidence: Does the interviewee present themselves confidently and effectively communicate their ideas?
|
| 113 |
+
7. Fit: Does the response demonstrate how the interviewee's skills, experiences, or qualifications align with the job requirement?
|
| 114 |
+
|
| 115 |
+
C) 3 point system: The user to be evaluated on the following criteria with a 3 point system:
|
| 116 |
+
|
| 117 |
+
1. Clarity: Spoken language is clear and is easily understood Comment
|
| 118 |
+
|
| 119 |
+
3 Is an exemplary Interviewee who is always understood.
|
| 120 |
+
2 Spoken language is clear and is easily understood
|
| 121 |
+
1 Spoken language is unclear or not easily understood
|
| 122 |
+
|
| 123 |
+
2. Comfort Level
|
| 124 |
+
|
| 125 |
+
3 Appears completely self-assured with the Interviewer
|
| 126 |
+
2 Appears comfortable with the Interviewer
|
| 127 |
+
1 Appears highly uncomfortable with the Interviewer
|
| 128 |
+
|
| 129 |
+
3. Interesting content: Engages Interviewer with interesting, well-constructed content Comment
|
| 130 |
+
|
| 131 |
+
3 Fully engages Interviewer with exemplary, well constructed content
|
| 132 |
+
2 Engages Interviewer with interesting, well constructed content
|
| 133 |
+
1 Content is neither interesting nor well-constructed
|
| 134 |
+
|
| 135 |
+
4. Well Supported: Speech content is well-supported and sources are available if requested
|
| 136 |
+
|
| 137 |
+
3 Delivers exemplary speech with a topic that is well-supported by content of the speech
|
| 138 |
+
2 Speech topic is well-supported by content of speech
|
| 139 |
+
1 Speech content is unrelated to the topic of the speech
|
| 140 |
+
|
| 141 |
+
Assess the response and give your honest feedback.
|
| 142 |
+
A) Language
|
| 143 |
+
B) Tone & personality
|
| 144 |
+
C) 3 point evaluation: Overall Score = sum of points scored "/" 12
|
| 145 |
+
|
| 146 |
+
Put in top 3 bullet points for feedback + 3 bullet points on how to improve it.
|
| 147 |
+
|
| 148 |
+
Response:
|
| 149 |
+
{transcribed_text}
|
| 150 |
+
"""
|
| 151 |
+
|
| 152 |
+
# Call the OpenAI API
|
| 153 |
+
api_response = openai.Completion.create(
|
| 154 |
+
engine="text-davinci-003", # Use "text-davinci-002" for GPT-3.5, replace with the appropriate engine name for GPT-4 if available
|
| 155 |
+
prompt=prompt,
|
| 156 |
+
temperature=0,
|
| 157 |
+
max_tokens=500,
|
| 158 |
+
top_p=1.0,
|
| 159 |
+
frequency_penalty=0.0,
|
| 160 |
+
presence_penalty=0.0
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
# Extract and return the generated feedback
|
| 164 |
+
feedback = api_response.choices[0].text.strip()
|
| 165 |
+
|
| 166 |
+
language = "en"
|
| 167 |
+
audioobj = gTTS(text = feedback,
|
| 168 |
+
lang = language,
|
| 169 |
+
slow = False)
|
| 170 |
+
|
| 171 |
+
audioobj.save("Temp.mp3")
|
| 172 |
+
|
| 173 |
+
return [feedback, transcribed_text, "Temp.mp3"]
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
# iface = gr.Interface(
|
| 178 |
+
# fn=get_feedback,
|
| 179 |
+
# inputs=gr.inputs.Textbox(lines=10, label="Interviewee audio file path"),
|
| 180 |
+
# outputs=[
|
| 181 |
+
# gr.outputs.Textbox(label="Feedback"),
|
| 182 |
+
# gr.outputs.Textbox(label="Transcription")
|
| 183 |
+
# ],
|
| 184 |
+
# title="Interview Feedback",
|
| 185 |
+
# examples=[
|
| 186 |
+
# "Tell me about yourself - bad graduate job interview answer tell me about yourselfout.mp3",
|
| 187 |
+
# "Tell me about yourself - bad entrepreneur answer to tell me about yourselfout.mp3"
|
| 188 |
+
# ],
|
| 189 |
+
# description="Get feedback on your interview response from an AI interview coach.",
|
| 190 |
+
# layout="vertical"
|
| 191 |
+
# )
|
| 192 |
+
|
| 193 |
+
# iface.launch()
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
# Create a Gradio interface
|
| 197 |
+
# the layout should be input, examples, feedback, transcription
|
| 198 |
+
# the input should be a textbox
|
| 199 |
+
# the examples should be a list of audio files
|
| 200 |
+
# the output should be a textbox for feedback and a textbox for transcription
|
| 201 |
+
|
| 202 |
+
iface = gr.Interface(
|
| 203 |
+
fn=get_feedback,
|
| 204 |
+
inputs=gr.inputs.Textbox(lines=10, label="Interviewee audio file path"),
|
| 205 |
+
outputs=[
|
| 206 |
+
gr.outputs.Textbox(label="Feedback"),
|
| 207 |
+
gr.outputs.Textbox(label="Transcription"),
|
| 208 |
+
gr.Audio("Temp.mp3", label="Speech Output")
|
| 209 |
+
],
|
| 210 |
+
title="Interview Feedback",
|
| 211 |
+
examples=[
|
| 212 |
+
"Tell me about yourself - bad graduate job interview answer tell me about yourselfout.mp3",
|
| 213 |
+
"Tell me about yourself - bad entrepreneur answer to tell me about yourselfout.mp3"
|
| 214 |
+
],
|
| 215 |
+
description="Get feedback on your interview response from an AI interview coach.",
|
| 216 |
+
layout="vertical"
|
| 217 |
+
)
|
| 218 |
+
iface.launch()
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
#########################################################################################
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai
|
| 2 |
+
whisper
|
| 3 |
+
pytube
|
| 4 |
+
moviepy
|
| 5 |
+
pydub
|
| 6 |
+
gradio
|
| 7 |
+
gtts
|