WaveOAK's picture
Update app.py
0db7dc4 verified
import whisper
import gradio as gr
import requests
import os
# Load the Magic Ear (Whisper)
model = whisper.load_model("base")
def transcribe_audio(audio_filepath):
if audio_filepath is None:
return "Please upload an audio file first!"
# Transcribe
result = model.transcribe(audio_filepath)
return result["text"]
def summarize_text(text):
# --- THIS IS THE FIX ---
# We ask for the NAME of the secret, not the key itself
api_key = os.getenv("GROQ_API_KEY")
# -----------------------
if not api_key:
return "Error: API Key is missing. Please set it in Settings!"
url = "https://api.groq.com/openai/v1/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
data = {
"model": "llama3-8b-8192",
"messages": [
{"role": "system", "content": "You are a helpful assistant. Summarize this meeting transcript into 3-5 clear bullet points."},
{"role": "user", "content": text}
]
}
try:
response = requests.post(url, json=data, headers=headers)
return response.json()['choices'][0]['message']['content']
except Exception as e:
return f"Error connecting to Storyteller: {str(e)}"
def process_meeting(audio):
transcript = transcribe_audio(audio)
summary = summarize_text(transcript)
return transcript, summary
# Build the Interface
app = gr.Interface(
fn=process_meeting,
inputs=gr.Audio(type="filepath"),
outputs=[
gr.Textbox(label="Full Transcript"),
gr.Textbox(label="Meeting Minutes")
],
title="AI Meeting Assistant",
description="Upload an audio file to generate a transcript and summary."
)
if __name__ == "__main__":
app.launch()