|
import gradio as gr |
|
import torch |
|
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, TextStreamer |
|
|
|
|
|
WHISPER_MODEL = "openai/whisper-large-v3" |
|
DEVICE = "cuda" if torch.cuda.is_available() else "cpu" |
|
|
|
transcriber = pipeline( |
|
task="automatic-speech-recognition", |
|
model=WHISPER_MODEL, |
|
chunk_length_s=30, |
|
device=DEVICE, |
|
) |
|
|
|
|
|
LLAMA = "meta-llama/Llama-2-7b-chat-hf" |
|
quant_config = BitsAndBytesConfig( |
|
load_in_4bit=True, |
|
bnb_4bit_use_double_quant=True, |
|
bnb_4bit_compute_dtype=torch.bfloat16, |
|
bnb_4bit_quant_type="nf4" |
|
) |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(LLAMA) |
|
tokenizer.pad_token = tokenizer.eos_token |
|
model = AutoModelForCausalLM.from_pretrained(LLAMA, device_map="auto", quantization_config=quant_config) |
|
|
|
|
|
def process_audio(audio_file): |
|
if audio_file is None: |
|
return "Error: No audio provided!" |
|
|
|
|
|
transcript = transcriber(audio_file)["text"] |
|
|
|
|
|
system_message = "You are an assistant that produces minutes of meetings from transcripts, with summary, key discussion points, takeaways and action items with owners, in markdown." |
|
user_prompt = f"Below is an extract transcript of a Denver council meeting. Please write minutes in markdown, including a summary with attendees, location and date; discussion points; takeaways; and action items with owners.\n{transcript}" |
|
|
|
messages = [ |
|
{"role": "system", "content": system_message}, |
|
{"role": "user", "content": user_prompt} |
|
] |
|
|
|
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(DEVICE) |
|
streamer = TextStreamer(tokenizer) |
|
outputs = model.generate(inputs, max_new_tokens=2000, streamer=streamer) |
|
|
|
return tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
interface = gr.Interface( |
|
fn=process_audio, |
|
inputs=gr.Audio(sources=["upload", "microphone"], type="filepath"), |
|
outputs="text", |
|
title="Meeting Minutes Generator", |
|
description="Upload or record an audio file to get structured meeting minutes in Markdown.", |
|
) |
|
|
|
|
|
interface.launch() |
|
|