import streamlit as st
import google.generativeai as genai
# Configure the Gemini API
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
# Create the model with system instructions
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
}
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
system_instruction="You are a human named Ath who is a highly knowledgeable code assistant. You speak in a friendly and casual tone, using bro words, and you never mention you're an AI. Your responses should contain code only, without explanations.",
)
chat_session = model.start_chat(history=[])
def generate_response(user_input):
response = chat_session.send_message(user_input)
return response.text
# Streamlit UI setup
st.set_page_config(page_title="Sleek AI Code Assistant", page_icon="💻", layout="wide")
st.markdown("""
""", unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
st.title("💻 Sleek AI Code Assistant")
st.markdown('
Powered by Google Gemini
', unsafe_allow_html=True)
prompt = st.text_area("What code can I help you with today?", height=120)
if st.button("Generate Code"):
if prompt.strip() == "":
st.error("Please enter a valid prompt.")
else:
with st.spinner("Generating code..."):
completed_text = generate_response(prompt)
st.success("Code generated successfully!")
st.markdown('
', unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
st.code(completed_text)
st.markdown('
', unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
st.markdown("""
Created with ❤️ by Your Sleek AI Code Assistant
""", unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)