|
import gradio as gr |
|
import threading |
|
import time |
|
import os |
|
from twilio.rest import Client |
|
import google.generativeai as genai |
|
|
|
|
|
TWILIO_SID = os.getenv('TWILIO_SID') |
|
TWILIO_TOKEN = os.getenv('TWILIO_TOKEN') |
|
GEMINI_KEY = os.getenv('GEMINI_KEY') |
|
|
|
|
|
twilio_client = Client(TWILIO_SID, TWILIO_TOKEN) |
|
|
|
|
|
gemini_client = genai.GenerativeModel('gemini-2.0-flash-lite') |
|
|
|
|
|
def set_call_info(number, passcode): |
|
global DIAL_IN_NUMBER, PASSCODE |
|
DIAL_IN_NUMBER = f"1{number}" |
|
PASSCODE = passcode |
|
return "Call information set successfully." |
|
|
|
|
|
def live_transcription(): |
|
|
|
transcription_chunks = [] |
|
for i in range(10): |
|
chunk = gemini_client.generate_text(f"Transcription chunk {i}") |
|
transcription_chunks.append(chunk) |
|
time.sleep(1) |
|
return transcription_chunks |
|
|
|
|
|
def stitch_transcription_chunks(chunks): |
|
return ' '.join(chunks) |
|
|
|
|
|
def generate_meeting_minutes(transcript): |
|
return gemini_client.generate_text(f"Meeting minutes based on: {transcript}") |
|
|
|
|
|
def download_as_word(text, filename): |
|
doc = Document() |
|
doc.add_paragraph(text) |
|
doc.save(filename) |
|
return filename |
|
|
|
|
|
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) |