Spaces:
Sleeping
Sleeping
| 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) | |