Spaces:
Sleeping
Sleeping
File size: 1,315 Bytes
2774330 |
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 35 36 37 38 39 40 41 42 43 44 45 |
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)
|