Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
# ✅ Ensure this is the first Streamlit command
|
| 6 |
+
st.set_page_config(page_title="Gemini Chatbot", layout="wide")
|
| 7 |
+
|
| 8 |
+
st.markdown("""
|
| 9 |
+
<h1 style="text-align:center; color: #FF4500;">Welcome To Gemini CodeReviewer using Gemini API.....</h1>
|
| 10 |
+
""", unsafe_allow_html=True)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
import google.generativeai as genai
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Configure Gemini API Key
|
| 17 |
+
genai.configure(api_key="AIzaSyBNuAnoR316s3mlaVY6zsgtmarKR4ZbajE")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Function to get Gemini response
|
| 21 |
+
def get_gemini_response(prompt):
|
| 22 |
+
model = genai.GenerativeModel("models/gemini-2.0-flash")
|
| 23 |
+
response = model.generate_content(prompt)
|
| 24 |
+
return response.text if response.text else "Sorry, I couldn't understand that."
|
| 25 |
+
|
| 26 |
+
# Chat interface
|
| 27 |
+
if "messages" not in st.session_state:
|
| 28 |
+
st.session_state.messages = []
|
| 29 |
+
|
| 30 |
+
for message in st.session_state.messages:
|
| 31 |
+
with st.chat_message(message["role"]):
|
| 32 |
+
st.markdown(message["content"])
|
| 33 |
+
|
| 34 |
+
user_input = st.chat_input("Type your message...")
|
| 35 |
+
|
| 36 |
+
if user_input:
|
| 37 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 38 |
+
with st.chat_message("user"):
|
| 39 |
+
st.markdown(user_input)
|
| 40 |
+
|
| 41 |
+
response = get_gemini_response(user_input)
|
| 42 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 43 |
+
with st.chat_message("assistant"):
|
| 44 |
+
st.markdown(response)
|