Skip to content

Commit

Permalink
improve prompt and code
Browse files Browse the repository at this point in the history
  • Loading branch information
gksoriginals committed Nov 23, 2023
1 parent 12f5b6c commit 7d84a39
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
1 change: 1 addition & 0 deletions prompts/thanks_prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generate a thank you message quoting the speaker's speech given below:\n\n
1 change: 1 addition & 0 deletions prompts/transcript_prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generate a full transcript for an event. The transcript should start with a greeting and a welcome message, followed by inviting each speaker to the stage. Each speaker's invitation should end with the special character ###. The invitations should have only dialogues without any headings or labels like "host:". In the last part end the event with thanking all speakers and the attendees. The speaker details are as follows:
22 changes: 3 additions & 19 deletions src/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@
)


def generate_transcript(document, client: OpenAI):
prompt = "Generate a full transcript for an event. \
The transcript should start with a greeting and welcome to the event message. \
Then, introduce each speaker and invite them to the stage. \
Write each speaker welcome as separate paragraph. \
The speaker details are as follows:\n\n"

transcript = generate_text_with_prompt(document, prompt, client)
return transcript


def generate_and_save_transcript(pdf_file, client: OpenAI):
def generate_and_save_transcript(pdf_file, prompt, client: OpenAI):
# Load the PDF file
document = load_pdf_file(pdf_file)

# Generate the transcript
transcript = generate_transcript(document, client)
transcript = generate_text_with_prompt(document, prompt, client)

with open(os.path.join('..', 'transcripts', os.path.basename(pdf_file).replace('.pdf', '.txt')), 'w') as f:
f.write(transcript)
Expand All @@ -38,9 +27,4 @@ def load_transcript(filename):
transcript = file.read()

# Return the contents of the file
return transcript


def generate_thank_you_message(speech, client: OpenAI):
prompt = "Generate a thank you message quoting the speaker's speech given below:\n\n"
return generate_text_with_prompt(speech, prompt, client)
return transcript
3 changes: 2 additions & 1 deletion src/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import keyboard
from vision import has_speaker_left_stage
import scipy.io.wavfile as wav
import cv2


def speak(text, client: OpenAI):
Expand Down Expand Up @@ -80,7 +81,7 @@ def record_speech_vision(fs=44100):
return filename


def speech_to_text(filename, client: OpenAI):
def transcribe(filename, client: OpenAI):
# Open the audio file in binary mode
with open(filename, 'rb') as audio_file:
# Convert the audio file to text using OpenAI's Whisper ASR API
Expand Down
15 changes: 11 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@
api_key=os.environ.get("OPENAI_API_KEY"),
)

with open("prompts/transcript_prompt.txt", 'r') as f:
transcript_prompt = f.read()

with open("prompts/thanks_prompt.txt", 'r') as f:
thanks_prompt = f.read()

def main():
parser = argparse.ArgumentParser(description='AI Event Host')
parser.add_argument('command', help='Command to execute')
parser.add_argument('pdf_file', help='PDF file with speaker details')
args = parser.parse_args()

if args.command == 'generate':
ai.generate_and_save_transcript(args.pdf_file, client)
ai.generate_and_save_transcript(args.pdf_file, transcript_prompt, client)
elif args.command == 'start':
transcript = ai.load_transcript(args.pdf_file)
for dialogue in transcript.split('\n\n'):
dialogues = transcript.split('###')
for dialogue in dialogues:
audio.speak(dialogue, client)
speech = audio.record_speech()
text = audio.speech_to_text(speech, client)
thank_you_message = ai.generate_thank_you_message(text, client)
text = audio.transcribe(speech, client)
thank_you_message = ai.generate_text_with_prompt(text, thanks_prompt, client)
audio.speak(thank_you_message, client)

if __name__ == '__main__':
Expand Down

0 comments on commit 7d84a39

Please sign in to comment.