Code / app.py
Artificial-superintelligence's picture
Update app.py
e705807 verified
raw
history blame
4.82 kB
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 enhanced system instructions
generation_config = {
"temperature": 0.7,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 10240,
}
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
system_instruction="""You are Ath, a highly knowledgeable and skilled code assistant with expertise across multiple programming languages, frameworks, and paradigms. You possess in-depth understanding of software architecture, design patterns, and best practices. Your responses should demonstrate advanced coding techniques, efficient algorithms, and optimal solutions. Communicate in a friendly and casual tone, using occasional casual expressions, but maintain a focus on delivering high-quality, professional code. Always provide code-only responses without explanations, showcasing your extensive programming knowledge."""
)
chat_session = model.start_chat(history=[])
def generate_response(user_input):
try:
response = chat_session.send_message(user_input)
return response.text
except Exception as e:
return f"An error occurred: {e}"
# Streamlit UI setup
st.set_page_config(page_title="Advanced AI Code Assistant", page_icon="πŸ’»", layout="wide")
st.markdown("""
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #f0f4f8;
color: #1a202c;
}
.stApp {
max-width: 1000px;
margin: 0 auto;
padding: 2rem;
}
.main-container {
background: #ffffff;
border-radius: 16px;
padding: 2rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}
h1 {
font-size: 2.5rem;
font-weight: 700;
color: #2d3748;
text-align: center;
margin-bottom: 1rem;
}
.subtitle {
font-size: 1.1rem;
text-align: center;
color: #4a5568;
margin-bottom: 2rem;
}
.stTextArea textarea {
border: 2px solid #e2e8f0;
border-radius: 8px;
font-size: 1rem;
padding: 0.75rem;
transition: all 0.3s ease;
}
.stTextArea textarea:focus {
border-color: #4299e1;
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
}
.stButton button {
background-color: #4299e1;
color: white;
border: none;
border-radius: 8px;
font-size: 1.1rem;
font-weight: 600;
padding: 0.75rem 2rem;
transition: all 0.3s ease;
width: 100%;
}
.stButton button:hover {
background-color: #3182ce;
}
.output-container {
background: #f7fafc;
border-radius: 8px;
padding: 1rem;
margin-top: 2rem;
}
.code-block {
background-color: #2d3748;
color: #e2e8f0;
font-family: 'Fira Code', monospace;
font-size: 0.9rem;
border-radius: 8px;
padding: 1rem;
margin-top: 1rem;
overflow-x: auto;
}
.stAlert {
background-color: #ebf8ff;
color: #2b6cb0;
border-radius: 8px;
border: none;
padding: 0.75rem 1rem;
}
.stSpinner {
color: #4299e1;
}
</style>
""", unsafe_allow_html=True)
st.markdown('<div class="main-container">', unsafe_allow_html=True)
st.title("πŸ’» Advanced AI Code Assistant")
st.markdown('<p class="subtitle">Powered by Google Gemini - Expert-level coding solutions</p>', unsafe_allow_html=True)
prompt = st.text_area("What advanced coding challenge can I assist you with today?", height=120)
if st.button("Generate Expert Code"):
if prompt.strip() == "":
st.error("Please enter a valid prompt.")
else:
with st.spinner("Generating advanced code solution..."):
completed_text = generate_response(prompt)
if "An error occurred" in completed_text:
st.error(completed_text)
else:
st.success("Expert-level code generated successfully!")
st.markdown('<div class="output-container">', unsafe_allow_html=True)
st.markdown('<div class="code-block">', unsafe_allow_html=True)
st.code(completed_text)
st.markdown('</div>', unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)
st.markdown("""
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
Crafted with ❀️ by Your Advanced AI Code Assistant
</div>
""", unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)