File size: 1,068 Bytes
9b32601
 
 
 
a67efb3
9b32601
 
 
dd2349e
9b32601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
import streamlit as st
import google.generativeai as genai

# ------------------ CONFIG ------------------
GEMINI_API_KEY = "AIzaSyCUvVt745VPj9SSfxJkXVs4U4pmvjG0nJA" 
genai.configure(api_key=GEMINI_API_KEY)

# Initialize model
model = genai.GenerativeModel('gemini-2.5-flash')

# ------------------ STREAMLIT UI ------------------
st.set_page_config(page_title="Gemini Chatbot", page_icon="💬")
st.title("💬 Gemini AI Chatbot")
st.write("Talk with Google's Gemini model in real-time!")

# Create a chat session
if "chat_session" not in st.session_state:
    st.session_state.chat_session = model.start_chat(history=[])

# Input box
user_input = st.text_input("You:", placeholder="Type your message here...")

# When user sends a message
if user_input:
    try:
        response = st.session_state.chat_session.send_message(user_input)
        st.markdown(f"**Gemini:** {response.text}")
    except Exception as e:
        st.error(f"Error: {e}")

# Optional: show chat history
if st.button("Show Chat History"):
    st.write(st.session_state.chat_session.history)