initial test run
Browse files- app.py +72 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tempfile
|
| 3 |
+
|
| 4 |
+
import torch
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from transformers import pipeline
|
| 7 |
+
|
| 8 |
+
from huggingface_hub import notebook_login, InferenceClient
|
| 9 |
+
|
| 10 |
+
notebook_login()
|
| 11 |
+
|
| 12 |
+
TEXT_MODEL_NAME = "microsoft/Phi-3-mini-4k-instruct"
|
| 13 |
+
|
| 14 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
| 15 |
+
|
| 16 |
+
AUDIO_MODEL_NAME = (
|
| 17 |
+
"distil-whisper/distil-large-v3"
|
| 18 |
+
)
|
| 19 |
+
BATCH_SIZE = 8
|
| 20 |
+
|
| 21 |
+
pipe = pipeline(
|
| 22 |
+
task="automatic-speech-recognition",
|
| 23 |
+
model=AUDIO_MODEL_NAME,
|
| 24 |
+
chunk_length_s=30,
|
| 25 |
+
device=device,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
def transcribe(audio_input):
|
| 29 |
+
"""Function to convert audio to text."""
|
| 30 |
+
if audio_input is None:
|
| 31 |
+
raise gr.Error("No audio file submitted.")
|
| 32 |
+
|
| 33 |
+
output = pipe(audio_input, batch_size=BATCH_SIZE,
|
| 34 |
+
generate_kwargs={"task": "transcribe"},
|
| 35 |
+
return_timestamps=True)
|
| 36 |
+
return output["text"]
|
| 37 |
+
|
| 38 |
+
client = InferenceClient()
|
| 39 |
+
|
| 40 |
+
def build_messages(meeting_transcript) -> list:
|
| 41 |
+
system_input = "You are an assitant that organizes meeting minutes."
|
| 42 |
+
user_input = """Take this raw meeting transcript and return an organized version.
|
| 43 |
+
Here is the transcript:
|
| 44 |
+
{meeting_transcript}
|
| 45 |
+
""".format(
|
| 46 |
+
meeting_transcript=meeting_transcript
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
messages = [
|
| 50 |
+
{"role": "system", "content": system_input},
|
| 51 |
+
{"role": "user", "content": user_input},
|
| 52 |
+
]
|
| 53 |
+
return messages
|
| 54 |
+
|
| 55 |
+
def organize_text(meeting_transcript):
|
| 56 |
+
messages = build_messages(meeting_transcript)
|
| 57 |
+
response = client.chat_completion(messages, model=TEXT_MODEL_NAME, max_tokens=250, seed=430)
|
| 58 |
+
return response.choices[0].message.content
|
| 59 |
+
|
| 60 |
+
def meeting_transcript_tool(audio_input):
|
| 61 |
+
meeting_text = transcribe(audio_input)
|
| 62 |
+
organized_text = organize_text(meeting_text)
|
| 63 |
+
return organized_text
|
| 64 |
+
|
| 65 |
+
demo = gr.Interface(
|
| 66 |
+
fn=meeting_transcript_tool,
|
| 67 |
+
inputs=gr.Audio(type="filepath"),
|
| 68 |
+
outputs=gr.Textbox(show_copy_button=True),
|
| 69 |
+
title="The Complete Meeting Transcription tool",
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|