File size: 654 Bytes
d002eed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import gradio as gr
import google.generativeai as genai
import os
# Replace with your actual Gemini API key
API_KEY = "AIzaSyBo8ZumjaR32q-wm-75lXxceQkhc5xZMmE"
genai.configure(api_key=API_KEY)
# Initialize the model
model = genai.GenerativeModel("gemini-2.0-flash")
# Function to handle chat
def chat_with_gemini(message, history):
try:
response = model.generate_content(message)
return response.text
except Exception as e:
return f"❌ Error: {str(e)}"
# Gradio interface
gr.ChatInterface(
fn=chat_with_gemini,
title="Gemini Chatbot",
description="Ask me anything!",
theme="soft"
).launch(debug=True)
|