Skip to content

Commit 11208cc

Browse files
Merge pull request #2756 from Inbaselvan-ayyanar/patch-7
Create Audio_Summarizer.py
2 parents 46dec87 + fb99761 commit 11208cc

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Audio_Summarizer.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import whisper
2+
import re
3+
import openai
4+
import os
5+
6+
def transcript_generator():
7+
# Load Whisper model
8+
model = whisper.load_model("base")
9+
10+
# Transcribe audio file
11+
result = model.transcribe("audio.mp4")
12+
13+
# Send the transcript to the summarizer
14+
provide_summarizer(result)
15+
16+
17+
def provide_summarizer(Text):
18+
# Set up Groq OpenAI-compatible API credentials
19+
openai.api_key = os.getenv("OPENAI_API_KEY", "your-api-key-here") # Replace or set in environment
20+
openai.api_base = "https://api.groq.com/openai/v1"
21+
22+
# Extract text from the Whisper result
23+
text_to_summarize = Text["text"]
24+
25+
# Send the transcription to Groq for summarization
26+
response = openai.ChatCompletion.create(
27+
model="llama3-8b-8192",
28+
messages=[
29+
{"role": "system", "content": "You are a helpful assistant who summarizes long text into bullet points."},
30+
{"role": "user", "content": f"Summarize the following:\n\n{text_to_summarize}"}
31+
]
32+
)
33+
34+
# Split the response into sentences
35+
summary = re.split(r'(?<=[.!?]) +', response["choices"][0]["message"]["content"])
36+
37+
# Save summary to file
38+
with open("summary.txt", "w+", encoding="utf-8") as file:
39+
for sentence in summary:
40+
cleaned = sentence.strip()
41+
if cleaned:
42+
file.write("- " + cleaned + "\n")
43+
44+
45+
if __name__ == "__main__":
46+
transcript_generator()

0 commit comments

Comments
 (0)