import gradio as gr import threading import time import os from twilio.rest import Client import google.generativeai as genai # Constants TWILIO_SID = os.getenv('TWILIO_SID') TWILIO_TOKEN = os.getenv('TWILIO_TOKEN') GEMINI_KEY = os.getenv('GEMINI_KEY') # Initialize Twilio client twilio_client = Client(TWILIO_SID, TWILIO_TOKEN) # Initialize Gemini client gemini_client = genai.GenerativeModel('gemini-2.0-flash-lite') # Function to set Dial-in number and Passcode def set_call_info(number, passcode): global DIAL_IN_NUMBER, PASSCODE DIAL_IN_NUMBER = f"1{number}" # Add '1' for US-based numbers PASSCODE = passcode return "Call information set successfully." # Function for live transcription using Gemini def live_transcription(): # Simulate a long call with live transcription using Gemini transcription_chunks = [] for i in range(10): # Simulate 10 chunks chunk = gemini_client.generate_text(f"Transcription chunk {i}") transcription_chunks.append(chunk) time.sleep(1) # Simulate processing time return transcription_chunks # Function to stitch transcription chunks def stitch_transcription_chunks(chunks): return ' '.join(chunks) # Function to generate meeting minutes using Gemini def generate_meeting_minutes(transcript): return gemini_client.generate_text(f"Meeting minutes based on: {transcript}") # Function to download transcript or meeting minutes as Word document def download_as_word(text, filename): doc = Document() doc.add_paragraph(text) doc.save(filename) return filename # Gradio Interface with gr.Blocks() as demo: gr.Markdown("## Call Transcription and Meeting Minutes Generator") with gr.Row(): dial_in_number = gr.Textbox(label="Dial-in Number (without '1')") passcode = gr.Textbox(label="Passcode") set_call_button = gr.Button("Set Call Information") set_call_button.click(set_call_info, inputs=[dial_in_number, passcode], outputs=gr.Textbox(label="Status")) with gr.Row(): hang_up_button = gr.Button("Hang Up") hang_up_button.click(lambda: "Call ended", outputs=gr.Textbox(label="Status")) with gr.Row(): transcription_output = gr.Textbox(label="Live Transcription Output") minutes_output = gr.Textbox(label="Meeting Minutes Output") download_button = gr.Button("Download Transcript and Minutes") download_button.click(lambda: download_as_word(f"{transcription_output.value}\n{minutes_output.value}", "output.docx"), outputs=gr.File(label="Download")) demo.launch(share=True)