chainlit_demo / app.py
Sebbe33's picture
Update app.py
d0ca99c verified
raw
history blame contribute delete
741 Bytes
import chainlit as cl
import os
import google.generativeai as genai
# Configure Gemini
GOOGLE_API_KEY = os.environ.get("GEMINI_API_KEY")
if not GOOGLE_API_KEY:
raise ValueError("GEMINI_API_KEY not found")
genai.configure(api_key=GOOGLE_API_KEY)
# Initialize the Gemini Flash model
model = genai.GenerativeModel('gemini-2.0-flash')
@cl.on_chat_start
async def start_chat():
await cl.Message(
content="Hello! I'm a chatbot powered by Gemini Flash. How can I help you today?"
).send()
@cl.on_message
async def main(message: cl.Message):
# Generate response using Gemini
response = model.generate_content(message.content)
# Send response
await cl.Message(
content=response.text
).send()