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(""" """, unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.title("💻 Advanced AI Code Assistant") st.markdown('

Powered by Google Gemini - Expert-level coding solutions

', 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('
', 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("""
Crafted with ❤️ by Your Advanced AI Code Assistant
""", unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True)