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="CodeCraft AI", page_icon="🧠", layout="wide") st.markdown(""" """, unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.title("🧠 CodeCraft AI") st.markdown('

Empowering Developers with Advanced AI-Driven Solutions

', unsafe_allow_html=True) # Add language selection languages = ["Python", "JavaScript", "Java", "C++", "Ruby", "Go", "Rust", "TypeScript", "PHP", "Swift"] selected_language = st.selectbox("Select your preferred programming language:", languages) prompt = st.text_area(f"What {selected_language} challenge can I assist you with today?", height=120) col1, col2 = st.columns([3, 1]) with col1: generate_button = st.button("Generate Expert Code") with col2: complexity = st.select_slider("Code Complexity", options=["Low", "Medium", "High"]) if generate_button: if prompt.strip() == "": st.error("Please enter a valid prompt.") else: with st.spinner(f"Crafting {complexity.lower()} complexity {selected_language} solution..."): completed_text = generate_response(f"{complexity} complexity {selected_language} code for: {prompt}") if "An error occurred" in completed_text: st.error(completed_text) else: st.success(f"Expert-level {selected_language} code generated successfully!") st.markdown('
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.code(completed_text, language=selected_language.lower()) st.markdown('
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) # Add copy to clipboard button st.markdown( f""" """, unsafe_allow_html=True ) st.markdown("""
Engineered with 💡 by CodeCraft AI - Elevating Your Coding Experience
""", unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True)