import google.generativeai as genai
import os
import sys
from dotenv import load_dotenv
from typing import List, Dict

load_dotenv()

# Configuration
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))

if not os.getenv("GOOGLE_API_KEY"):
    print("Error: Google API key not found. Please set the GOOGLE_API_KEY environment variable.")
    sys.exit(1)

model = genai.GenerativeModel("gemini-1.5-flash")

# Helper Functions
def generate_question(conversation_history: List[Dict]) -> str:
    """Generates the next question based on the conversation history."""
    try:
        prompt = ""
        for turn in conversation_history:
            prompt += f"{turn['role']}: {turn['content']}\n"  # Add each turn

        prompt += "Assistant:"  # Indicate it's the assistant's turn now
  # Create model instance here
        response = model.generate_content(prompt)
        message = response.text.strip()
        return message

    except Exception as e:
        print(f"An error occurred while communicating with Gemini: {e}")
        sys.exit(1)
def display_welcome():
    """Displays the welcome message."""
    welcome_message = (
        "Welcome! This questionnaire is designed to help you understand your reproductive health better. "
        "Please answer the following questions honestly to receive a personalized assessment."
    )
    print("\n" + welcome_message + "\n")

def display_final_message(responses: str):
    """Displays a summary or recommendations based on user responses."""
    summary_prompt = (
        "Based on the following user responses, provide a summary and any recommendations:\n\n"
        f"{responses}"
    )
    try:
        response = model.generate_content(summary_prompt)
        summary = response.text.strip()
        print("\n" + summary + "\n")
    except Exception as e:
        print(f"An error occurred while generating the summary: {e}")
        sys.exit(1)


# Main Application
def main():
    conversation_history = [
        {"role": "system", "content": (
            "You are an interactive assistant designed to conduct an adaptive questionnaire "
            "to help users identify potential reproductive health issues. Your responses should be "
            "clear, empathetic, and tailored based on the user's previous answers."
        )}
    ]

    display_welcome()

    responses = {}
    question_number = 1
    while True:
        next_question = generate_question(conversation_history)
        print(f"Question {question_number}: {next_question}")

        user_input = input("Your Answer (type 'exit', 'quit', 'done', or 'finished' to end): ").strip()

        if user_input.lower() in ['exit', 'quit', 'done', 'finished']:
            print("\nThank you for participating. Stay healthy!")
            break

        conversation_history.append({"role": "user", "content": user_input})

        responses[f"Q{question_number}"] = {
            "question": next_question,
            "answer": user_input
        }
        question_number += 1

    if responses:
        print("\nGenerating summary based on your responses...")
        response_text = "\n".join(
            f"{qa['question']}\nAnswer: {qa['answer']}\n" for q_num, qa in responses.items()
        )
        display_final_message(response_text)

if __name__ == "__main__":
    main()

how can i add a audio which sounds like a doctor, the audio should sound very empathtic 
how to tell me please