chatbot / app.py
Gowthamvemula's picture
Update app.py
2774330 verified
import streamlit as st
# βœ… Ensure this is the first Streamlit command
st.set_page_config(page_title="Gemini Chatbot", layout="wide")
st.markdown("""
<h1 style="text-align:center; color: #FF4500;">Welcome To Gemini CodeReviewer using Gemini API.....</h1>
""", unsafe_allow_html=True)
import google.generativeai as genai
# Configure Gemini API Key
genai.configure(api_key="AIzaSyBNuAnoR316s3mlaVY6zsgtmarKR4ZbajE")
# Function to get Gemini response
def get_gemini_response(prompt):
model = genai.GenerativeModel("models/gemini-2.0-flash")
response = model.generate_content(prompt)
return response.text if response.text else "Sorry, I couldn't understand that."
# Chat interface
if "messages" not in st.session_state:
st.session_state.messages = []
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
user_input = st.chat_input("Type your message...")
if user_input:
st.session_state.messages.append({"role": "user", "content": user_input})
with st.chat_message("user"):
st.markdown(user_input)
response = get_gemini_response(user_input)
st.session_state.messages.append({"role": "assistant", "content": response})
with st.chat_message("assistant"):
st.markdown(response)