(Text)
| 16 | |
| 17 | |
| 18 | def provide_summarizer(Text): |
| 19 | # Set up Groq OpenAI-compatible API credentials |
| 20 | openai.api_key = os.getenv( |
| 21 | "OPENAI_API_KEY", "your-api-key-here" |
| 22 | ) # Replace or set in environment |
| 23 | openai.api_base = "https://api.groq.com/openai/v1" |
| 24 | |
| 25 | # Extract text from the Whisper result |
| 26 | text_to_summarize = Text["text"] |
| 27 | |
| 28 | # Send the transcription to Groq for summarization |
| 29 | response = openai.ChatCompletion.create( |
| 30 | model="llama3-8b-8192", |
| 31 | messages=[ |
| 32 | { |
| 33 | "role": "system", |
| 34 | "content": "You are a helpful assistant who summarizes long text into bullet points.", |
| 35 | }, |
| 36 | { |
| 37 | "role": "user", |
| 38 | "content": f"Summarize the following:\n\n{text_to_summarize}", |
| 39 | }, |
| 40 | ], |
| 41 | ) |
| 42 | |
| 43 | # Split the response into sentences |
| 44 | summary = re.split(r"(?<=[.!?]) +", response["choices"][0]["message"]["content"]) |
| 45 | |
| 46 | # Save summary to file |
| 47 | with open("summary.txt", "w+", encoding="utf-8") as file: |
| 48 | for sentence in summary: |
| 49 | cleaned = sentence.strip() |
| 50 | if cleaned: |
| 51 | file.write("- " + cleaned + "\n") |
| 52 | |
| 53 | |
| 54 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected