import gradio as gr import os import requests # Configuration for both endpoints TRANSCRIPTION_ENDPOINT = "https://your-whisper-endpoint.endpoints.huggingface.cloud/api/v1/audio/transcriptions" SUMMARIZATION_ENDPOINT = "https://your-qwen-endpoint.endpoints.huggingface.cloud/v1/chat/completions" HF_TOKEN = os.getenv("HF_TOKEN") # Your Hugging Face Hub token # Headers for authentication headers = { "Authorization": f"Bearer {HF_TOKEN}" } def transcribe_audio(audio_file_path): """Transcribe audio using direct requests to the endpoint""" # Read audio file and prepare for upload with open(audio_file_path, "rb") as audio_file: files = {"file": audio_file.read()} # Make the request to the transcription endpoint response = requests.post(TRANSCRIPTION_ENDPOINT, headers=headers, files=files) if response.status_code == 200: result = response.json() return result.get("text", "No transcription available") else: return f"Error: {response.status_code} - {response.text}" def generate_summary(transcript): """Generate summary using requests to the chat completions endpoint""" prompt = f""" Analyze this meeting transcript and provide: 1. A concise summary of key points 2. Action items with responsible parties 3. Important decisions made Transcript: {transcript} Format with clear sections: ## Summary ## Action Items ## Decisions Made """ # Prepare the payload using the Messages API format payload = { "model": "your-qwen-endpoint-name", # Use the name of your endpoint "messages": [{"role": "user", "content": prompt}], "max_tokens": 1000, "temperature": 0.7, "stream": False } # Headers for chat completions chat_headers = { "Accept": "application/json", "Content-Type": "application/json", "Authorization": f"Bearer {HF_TOKEN}" } # Make the request response = requests.post(SUMMARIZATION_ENDPOINT, headers=chat_headers, json=payload) response.raise_for_status() # Parse the response result = response.json() return result["choices"][0]["message"]["content"] def process_meeting_audio(audio_file): """Main processing function that handles the complete workflow""" if audio_file is None: return "Please upload an audio file.", "" try: # Step 1: Transcribe the audio transcript = transcribe_audio(audio_file) # Step 2: Generate summary from transcript summary = generate_summary(transcript) return transcript, summary except Exception as e: return f"Error processing audio: {str(e)}", "" # Create Gradio interface app = gr.Interface( fn=process_meeting_audio, inputs=gr.Audio(label="Upload Meeting Audio", type="filepath"), outputs=[ gr.Textbox(label="Full Transcript", lines=10), gr.Textbox(label="Meeting Summary", lines=8), ], title="🎤 AI Meeting Notes", description="Upload audio to get instant transcripts and summaries.", ) if __name__ == "__main__": app.launch()