Spaces:
Sleeping
Sleeping
commit
Browse files
app.py
CHANGED
|
@@ -3,10 +3,11 @@ import os
|
|
| 3 |
import requests
|
| 4 |
import json
|
| 5 |
from langchain.tools import tool
|
| 6 |
-
import requests
|
| 7 |
from typing import TypedDict
|
| 8 |
from langgraph.graph import StateGraph
|
| 9 |
import gradio as gr
|
|
|
|
|
|
|
| 10 |
|
| 11 |
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
|
| 12 |
MODEL = "mistral-large-latest"
|
|
@@ -17,6 +18,15 @@ class State(TypedDict):
|
|
| 17 |
summary_json: dict
|
| 18 |
final_output: str
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def transcribe_audio(state: State) -> State:
|
| 21 |
model = WhisperModel("base", compute_type="float32")
|
| 22 |
segments, _ = model.transcribe(state["file_path"], beam_size=5, language="en")
|
|
@@ -24,17 +34,14 @@ def transcribe_audio(state: State) -> State:
|
|
| 24 |
transcript = " ".join(segment.text.strip() for segment in segments)
|
| 25 |
return {**state, "transcript": transcript}
|
| 26 |
|
| 27 |
-
|
| 28 |
def summarize_transcript(state: State) -> State:
|
| 29 |
prompt = f"""
|
| 30 |
You are an AI assistant summarizing meeting transcripts.
|
| 31 |
-
|
| 32 |
Extract the following:
|
| 33 |
1. Attendees (Names only, if possible)
|
| 34 |
2. Key Discussion Points (bullet format)
|
| 35 |
3. Action Items (with owner and deadline, if mentioned)
|
| 36 |
4. Decisions Made (if any)
|
| 37 |
-
|
| 38 |
Respond in this format:
|
| 39 |
{{
|
| 40 |
"attendees": [...],
|
|
@@ -42,7 +49,6 @@ Respond in this format:
|
|
| 42 |
"action_items": [...],
|
| 43 |
"decisions": [...]
|
| 44 |
}}
|
| 45 |
-
|
| 46 |
Transcript:
|
| 47 |
\"\"\"{state['transcript']}\"\"\"
|
| 48 |
"""
|
|
@@ -69,12 +75,12 @@ def format_output(state: State) -> State:
|
|
| 69 |
formatted += "π Decisions:\n" + "\n".join(f"- {d}" for d in summary["decisions"])
|
| 70 |
return {**state, "final_output": formatted}
|
| 71 |
|
|
|
|
| 72 |
builder = StateGraph(State)
|
| 73 |
builder.add_node("transcribe_audio", transcribe_audio)
|
| 74 |
builder.add_node("summarize_transcript", summarize_transcript)
|
| 75 |
builder.add_node("format_output", format_output)
|
| 76 |
|
| 77 |
-
# Link nodes
|
| 78 |
builder.set_entry_point("transcribe_audio")
|
| 79 |
builder.add_edge("transcribe_audio", "summarize_transcript")
|
| 80 |
builder.add_edge("summarize_transcript", "format_output")
|
|
@@ -82,44 +88,34 @@ builder.add_edge("summarize_transcript", "format_output")
|
|
| 82 |
graph = builder.compile()
|
| 83 |
|
| 84 |
def process_meeting(file):
|
| 85 |
-
print(f"Received file: {file}")
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
try:
|
| 90 |
final_state = graph.invoke(state)
|
| 91 |
-
print(f"Final State: {final_state}")
|
| 92 |
return final_state["final_output"]
|
| 93 |
except Exception as e:
|
| 94 |
print(f"Error: {e}")
|
| 95 |
return str(e)
|
| 96 |
|
| 97 |
-
|
| 98 |
with gr.Blocks() as demo:
|
| 99 |
gr.Markdown("### π€ MeetRecap - AI-Powered Meeting Summarizer")
|
| 100 |
gr.Markdown("""
|
| 101 |
-
Upload your audio file
|
| 102 |
""")
|
| 103 |
|
| 104 |
with gr.Row():
|
| 105 |
with gr.Column():
|
| 106 |
-
audio_input = gr.Audio(type="filepath", label="ποΈ Upload
|
| 107 |
submit_btn = gr.Button("π Summarize")
|
| 108 |
clear_btn = gr.Button("π§Ή Clear")
|
| 109 |
with gr.Column():
|
| 110 |
summary_output = gr.Textbox(label="π Meeting Summary", lines=20, max_lines=40)
|
| 111 |
|
| 112 |
-
# π Optional: Add example audios
|
| 113 |
-
# gr.Examples(
|
| 114 |
-
# examples=[
|
| 115 |
-
# "examples/example_meeting_1.wav",
|
| 116 |
-
# "examples/example_meeting_2.wav"
|
| 117 |
-
# ],
|
| 118 |
-
# inputs=audio_input,
|
| 119 |
-
# label="π§ Try Example Audio",
|
| 120 |
-
# examples_per_page=0
|
| 121 |
-
# )
|
| 122 |
-
|
| 123 |
submit_btn.click(fn=process_meeting, inputs=audio_input, outputs=summary_output)
|
| 124 |
clear_btn.click(lambda: (None, ""), outputs=[audio_input, summary_output])
|
|
|
|
| 125 |
demo.launch(share=True)
|
|
|
|
| 3 |
import requests
|
| 4 |
import json
|
| 5 |
from langchain.tools import tool
|
|
|
|
| 6 |
from typing import TypedDict
|
| 7 |
from langgraph.graph import StateGraph
|
| 8 |
import gradio as gr
|
| 9 |
+
from pydub import AudioSegment
|
| 10 |
+
import tempfile
|
| 11 |
|
| 12 |
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
|
| 13 |
MODEL = "mistral-large-latest"
|
|
|
|
| 18 |
summary_json: dict
|
| 19 |
final_output: str
|
| 20 |
|
| 21 |
+
def convert_to_wav(input_path: str) -> str:
|
| 22 |
+
if input_path.lower().endswith(".wav"):
|
| 23 |
+
return input_path # No conversion needed
|
| 24 |
+
else:
|
| 25 |
+
audio = AudioSegment.from_file(input_path)
|
| 26 |
+
temp_wav_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
| 27 |
+
audio.export(temp_wav_file.name, format="wav")
|
| 28 |
+
return temp_wav_file.name
|
| 29 |
+
|
| 30 |
def transcribe_audio(state: State) -> State:
|
| 31 |
model = WhisperModel("base", compute_type="float32")
|
| 32 |
segments, _ = model.transcribe(state["file_path"], beam_size=5, language="en")
|
|
|
|
| 34 |
transcript = " ".join(segment.text.strip() for segment in segments)
|
| 35 |
return {**state, "transcript": transcript}
|
| 36 |
|
|
|
|
| 37 |
def summarize_transcript(state: State) -> State:
|
| 38 |
prompt = f"""
|
| 39 |
You are an AI assistant summarizing meeting transcripts.
|
|
|
|
| 40 |
Extract the following:
|
| 41 |
1. Attendees (Names only, if possible)
|
| 42 |
2. Key Discussion Points (bullet format)
|
| 43 |
3. Action Items (with owner and deadline, if mentioned)
|
| 44 |
4. Decisions Made (if any)
|
|
|
|
| 45 |
Respond in this format:
|
| 46 |
{{
|
| 47 |
"attendees": [...],
|
|
|
|
| 49 |
"action_items": [...],
|
| 50 |
"decisions": [...]
|
| 51 |
}}
|
|
|
|
| 52 |
Transcript:
|
| 53 |
\"\"\"{state['transcript']}\"\"\"
|
| 54 |
"""
|
|
|
|
| 75 |
formatted += "π Decisions:\n" + "\n".join(f"- {d}" for d in summary["decisions"])
|
| 76 |
return {**state, "final_output": formatted}
|
| 77 |
|
| 78 |
+
# Graph setup
|
| 79 |
builder = StateGraph(State)
|
| 80 |
builder.add_node("transcribe_audio", transcribe_audio)
|
| 81 |
builder.add_node("summarize_transcript", summarize_transcript)
|
| 82 |
builder.add_node("format_output", format_output)
|
| 83 |
|
|
|
|
| 84 |
builder.set_entry_point("transcribe_audio")
|
| 85 |
builder.add_edge("transcribe_audio", "summarize_transcript")
|
| 86 |
builder.add_edge("summarize_transcript", "format_output")
|
|
|
|
| 88 |
graph = builder.compile()
|
| 89 |
|
| 90 |
def process_meeting(file):
|
| 91 |
+
print(f"Received file: {file}")
|
| 92 |
+
wav_path = convert_to_wav(file)
|
| 93 |
+
state = {"file_path": wav_path}
|
| 94 |
+
print(f"State initialized: {state}")
|
| 95 |
|
| 96 |
try:
|
| 97 |
final_state = graph.invoke(state)
|
| 98 |
+
print(f"Final State: {final_state}")
|
| 99 |
return final_state["final_output"]
|
| 100 |
except Exception as e:
|
| 101 |
print(f"Error: {e}")
|
| 102 |
return str(e)
|
| 103 |
|
|
|
|
| 104 |
with gr.Blocks() as demo:
|
| 105 |
gr.Markdown("### π€ MeetRecap - AI-Powered Meeting Summarizer")
|
| 106 |
gr.Markdown("""
|
| 107 |
+
Upload your audio file (e.g., `.wav`, `.mp3`, `.m4a`) or record it. You'll receive a structured meeting summary including Attendees, Key Points, Action Items, and Decisions.
|
| 108 |
""")
|
| 109 |
|
| 110 |
with gr.Row():
|
| 111 |
with gr.Column():
|
| 112 |
+
audio_input = gr.Audio(type="filepath", label="ποΈ Upload or Record Audio")
|
| 113 |
submit_btn = gr.Button("π Summarize")
|
| 114 |
clear_btn = gr.Button("π§Ή Clear")
|
| 115 |
with gr.Column():
|
| 116 |
summary_output = gr.Textbox(label="π Meeting Summary", lines=20, max_lines=40)
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
submit_btn.click(fn=process_meeting, inputs=audio_input, outputs=summary_output)
|
| 119 |
clear_btn.click(lambda: (None, ""), outputs=[audio_input, summary_output])
|
| 120 |
+
|
| 121 |
demo.launch(share=True)
|