Files changed (1) hide show
  1. app.py +102 -0
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import requests
4
+
5
+ # Configuration for both endpoints
6
+ TRANSCRIPTION_ENDPOINT = "https://your-whisper-endpoint.endpoints.huggingface.cloud/api/v1/audio/transcriptions"
7
+ SUMMARIZATION_ENDPOINT = "https://your-qwen-endpoint.endpoints.huggingface.cloud/v1/chat/completions"
8
+ HF_TOKEN = os.getenv("HF_TOKEN") # Your Hugging Face Hub token
9
+
10
+ # Headers for authentication
11
+ headers = {
12
+ "Authorization": f"Bearer {HF_TOKEN}"
13
+ }
14
+
15
+ def transcribe_audio(audio_file_path):
16
+ """Transcribe audio using direct requests to the endpoint"""
17
+
18
+ # Read audio file and prepare for upload
19
+ with open(audio_file_path, "rb") as audio_file:
20
+ files = {"file": audio_file.read()}
21
+
22
+ # Make the request to the transcription endpoint
23
+ response = requests.post(TRANSCRIPTION_ENDPOINT, headers=headers, files=files)
24
+
25
+ if response.status_code == 200:
26
+ result = response.json()
27
+ return result.get("text", "No transcription available")
28
+ else:
29
+ return f"Error: {response.status_code} - {response.text}"
30
+
31
+ def generate_summary(transcript):
32
+ """Generate summary using requests to the chat completions endpoint"""
33
+
34
+ prompt = f"""
35
+ Analyze this meeting transcript and provide:
36
+ 1. A concise summary of key points
37
+ 2. Action items with responsible parties
38
+ 3. Important decisions made
39
+
40
+ Transcript: {transcript}
41
+
42
+ Format with clear sections:
43
+ ## Summary
44
+ ## Action Items
45
+ ## Decisions Made
46
+ """
47
+
48
+ # Prepare the payload using the Messages API format
49
+ payload = {
50
+ "model": "your-qwen-endpoint-name", # Use the name of your endpoint
51
+ "messages": [{"role": "user", "content": prompt}],
52
+ "max_tokens": 1000,
53
+ "temperature": 0.7,
54
+ "stream": False
55
+ }
56
+
57
+ # Headers for chat completions
58
+ chat_headers = {
59
+ "Accept": "application/json",
60
+ "Content-Type": "application/json",
61
+ "Authorization": f"Bearer {HF_TOKEN}"
62
+ }
63
+
64
+ # Make the request
65
+ response = requests.post(SUMMARIZATION_ENDPOINT, headers=chat_headers, json=payload)
66
+ response.raise_for_status()
67
+
68
+ # Parse the response
69
+ result = response.json()
70
+ return result["choices"][0]["message"]["content"]
71
+
72
+ def process_meeting_audio(audio_file):
73
+ """Main processing function that handles the complete workflow"""
74
+ if audio_file is None:
75
+ return "Please upload an audio file.", ""
76
+
77
+ try:
78
+ # Step 1: Transcribe the audio
79
+ transcript = transcribe_audio(audio_file)
80
+
81
+ # Step 2: Generate summary from transcript
82
+ summary = generate_summary(transcript)
83
+
84
+ return transcript, summary
85
+
86
+ except Exception as e:
87
+ return f"Error processing audio: {str(e)}", ""
88
+
89
+ # Create Gradio interface
90
+ app = gr.Interface(
91
+ fn=process_meeting_audio,
92
+ inputs=gr.Audio(label="Upload Meeting Audio", type="filepath"),
93
+ outputs=[
94
+ gr.Textbox(label="Full Transcript", lines=10),
95
+ gr.Textbox(label="Meeting Summary", lines=8),
96
+ ],
97
+ title="🎤 AI Meeting Notes",
98
+ description="Upload audio to get instant transcripts and summaries.",
99
+ )
100
+
101
+ if __name__ == "__main__":
102
+ app.launch()