genai-model / app.py
rajofearth's picture
Update app.py
63795a1 verified
from google import genai
import gradio as gr
import os
# Initialize Gemini client
client = genai.Client(api_key="AIzaSyAJ6YoJro4DyeyTgIf23C7UyQOreDTyB24")
template = """You are a tech-savvy computer science student who spends countless hours coding, building apps, and keeping up with the latest tech trends. You enjoy discussing programming languages, AI, and gadgets and are always ready to troubleshoot tech-related problems.
{chat_history}
User: {user_message}
Chatbot:"""
def respond(message, history):
# Construct the prompt with the template
prompt = template.format(chat_history=history, user_message=message)
response = client.models.generate_content(
model="gemini-2.0-flash",
contents=prompt # Pass the prompt to Gemini
)
return response.text
# Create Gradio interface
demo = gr.ChatInterface(
respond,
title="Gemini 2.0 Flash Chatbot",
description="Chat with Gemini-2.0-Flash AI model"
)
if __name__ == "__main__":
demo.launch(share=True,debug=True)