GPT5_Demo / app.py
Abs6187's picture
Update app.py
92ba5c1 verified
raw
history blame
979 Bytes
# chat_app.py
import os
import gradio as gr
import google.generativeai as genai
# 1️⃣ Configure the SDK – read the key from an env-var
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
# 2️⃣ Create a model and a stateful chat session
model = genai.GenerativeModel("gemini-2.0-flash") # change model name if you like
chat = model.start_chat() # history handled for you
# 3️⃣ Callback that Gradio calls each turn
def respond(message, history):
reply = chat.send_message(message) # send the new user turn
return reply.text # only the assistant reply
# 4️⃣ Build the UI
iface = gr.ChatInterface(
fn=respond,
title="Gemini Chatbot",
chatbot=gr.Chatbot(height=600),
textbox=gr.Textbox(placeholder="Ask anything…"),
retry_btn="🔄 Retry",
clear_btn="🗑️ Clear",
)
# 5️⃣ Launch the app
if __name__ == "__main__":
iface.launch()