import google.generativeai as genai import gradio as gr import os # Import the os module for environment variables from dotenv import load_dotenv load_dotenv() # Get the API Key from Hugging Face Secrets api_key = os.getenv("GOOGLE") genai.configure(api_key=api_key) # Initialize model and chat (outside the function) model = genai.GenerativeModel("gemini-pro") chat = model.start_chat(history=[]) def get_gemini_response(question): response = chat.send_message(question, stream=True) full_response = "" for chunk in response: full_response += chunk.text return full_response # Interface using Gradio theme = gr.themes.Soft() with gr.Blocks(theme=theme, css=".gradio-container {background-color: #f0f5f9}") as demo: gr.Markdown( """
Ask me anything! 💬