import streamlit as st
import google.generativeai as genai
import requests
import subprocess
import os
# Configure the Gemini API
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
# Create the model with optimized parameters and enhanced system instructions
generation_config = {
"temperature": 0.7, # Lower temperature for more deterministic responses
"top_p": 0.85, # Adjusted for better diversity
"top_k": 40, # Increased for more diverse tokens
"max_output_tokens": 12288, # Increased for longer responses
}
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
system_instruction="""
You are Ath, 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 optimized code only, without explanations. You are designed to provide accurate, efficient, and high-quality code solutions.
"""
)
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"Error: {e}"
def optimize_code(code):
# Placeholder for code optimization logic
# This could involve using external tools or libraries for static analysis and optimization
return code
def fetch_from_github(query):
# Placeholder for fetching code snippets from GitHub
# This could involve using the GitHub API to search for relevant code
return ""
# 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)
if "Error" in completed_text:
st.error(completed_text)
else:
optimized_code = optimize_code(completed_text)
st.success("Code generated and optimized successfully!")
st.markdown('
', unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
st.code(optimized_code)
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)