AI_App / app.py
resolverkatla's picture
updated to Gemini 2.0 Flash
7ba8354
raw
history blame contribute delete
856 Bytes
import gradio as gr
import google.generativeai as genai
import os
# Set up Gemini API key (use environment variable on Hugging Face)
API_KEY = os.getenv("GEMINI_API_KEY") # Set this in Hugging Face secrets
genai.configure(api_key=API_KEY)
# Use Gemini 2.0 Flash (free-tier accessible)
model = genai.GenerativeModel("gemini-2.0-flash")
def chatbot(prompt, history=[]):
"""Generates a chatbot response using the free-tier Gemini API."""
try:
response = model.generate_content(prompt)
return response.text
except Exception as e:
return f"Error: {e}"
# Create Gradio chatbot interface
chat_interface = gr.ChatInterface(
chatbot,
title="Free Gemini API Chatbot",
description="A chatbot powered by the free-tier Google Gemini API.",
)
# Run the chatbot
if __name__ == "__main__":
chat_interface.launch()