import streamlit as st import google.generativeai as genai from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter import html import json import requests import base64 # Configure the Gemini API genai.configure(api_key=st.secrets["GOOGLE_API_KEY"]) # Create the model with highly enhanced system instructions focused on web design generation_config = { "temperature": 0.9, "top_p": 0.95, "top_k": 64, "max_output_tokens": 32768, } model = genai.GenerativeModel( model_name="gemini-1.5-pro", generation_config=generation_config, system_instruction="""You are WebGenius AI, a superintelligent AI assistant specializing in cutting-edge web design and development. Your knowledge encompasses: 1. Advanced front-end technologies (HTML5, CSS3, JavaScript ES2021+) 2. Modern web frameworks and libraries (React, Vue, Angular, Svelte) 3. State-of-the-art CSS frameworks and methodologies (Tailwind CSS, CSS-in-JS, CSS Modules) 4. Progressive Web Apps (PWAs) and Service Workers 5. Web Components and Shadow DOM 6. Server-Side Rendering (SSR) and Static Site Generation (SSG) 7. JAMstack architecture and headless CMS integration 8. WebAssembly and its applications in web development 9. Web accessibility (WCAG 2.1 AAA compliance) and inclusive design 10. Responsive and adaptive design techniques 11. Web animation and interactive user interfaces 12. Web performance optimization and Core Web Vitals 13. Cross-browser compatibility and graceful degradation 14. SEO best practices and structured data 15. Web security (HTTPS, CSP, CORS, XSS prevention) 16. API design (REST, GraphQL, gRPC) and backend integration 17. Serverless architectures and cloud deployment (AWS, Azure, GCP) 18. DevOps for web applications (CI/CD, containerization) 19. Web analytics and user behavior tracking 20. Emerging web technologies (Web3, decentralized apps, AR/VR for web) Your responses should demonstrate cutting-edge web design techniques, highly optimized code, and innovative solutions that push the boundaries of what's possible in modern web development. Always consider the latest web standards, emerging technologies, and best practices in your solutions. Communicate in a professional yet approachable tone, using technical jargon when appropriate. Your primary focus is on delivering exceptional, production-ready code and in-depth explanations that showcase your vast knowledge of web design and development. Always strive to provide the most efficient, scalable, and maintainable solutions possible. In addition to coding, offer insights on: - Latest trends in web design and their potential impact on user experience - Advanced performance optimization techniques for web applications - Cutting-edge UI/UX design patterns and their implementation - Comprehensive testing strategies for web applications - Scalability and high-availability architectures for web services - Cross-platform and multi-device web development strategies - Internationalization and localization best practices for websites - Ethical considerations in web design and development When asked, provide detailed explanations of your code, including the rationale behind your design decisions, any trade-offs considered, and potential optimizations. Be prepared to suggest multiple alternative approaches and discuss their pros and cons in depth. Your goal is to elevate the user's web design and development skills to the highest possible level, inspiring them to create innovative, accessible, and high-performance web experiences.""" ) 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}" def create_code_block(code, language): lexer = get_lexer_by_name(language, stripall=True) formatter = HtmlFormatter(style="monokai", linenos=True, cssclass="source") highlighted_code = highlight(code, lexer, formatter) css = formatter.get_style_defs('.source') return highlighted_code, css def fetch_latest_web_design_trends(): url = "https://api.example.com/web-design-trends" # Replace with a real API endpoint try: response = requests.get(url) trends = response.json() return trends[:5] # Return top 5 trends except: return [] def generate_color_palette(): url = "https://api.example.com/color-palette-generator" # Replace with a real API endpoint try: response = requests.get(url) palette = response.json() return palette except: return ["#3498db", "#2ecc71", "#e74c3c", "#f39c12", "#9b59b6"] # Fallback palette # Streamlit UI setup st.set_page_config(page_title="WebGenius AI - Advanced Web Design Assistant", page_icon="🎨", layout="wide") st.markdown(""" """, unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.title("🎨 WebGenius AI") st.markdown('

Advanced Web Design Assistant - Crafting the Future of the Web

', unsafe_allow_html=True) prompt = st.text_area("Describe your web design challenge or ask for cutting-edge web development advice:", height=120) if st.button("Generate Innovative Web Solution"): if prompt.strip() == "": st.error("Please enter a valid prompt.") else: with st.spinner("Crafting a state-of-the-art web solution..."): completed_text = generate_response(prompt) if "An error occurred" in completed_text: st.error(completed_text) else: st.success("Innovative web solution generated successfully!") # Improved language detection for web technologies languages = ["html", "css", "javascript", "typescript", "jsx", "vue", "svelte"] detected_language = next((lang for lang in languages if lang in completed_text.lower()), "html") highlighted_code, css = create_code_block(completed_text, detected_language) st.markdown(f'', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.markdown(highlighted_code, unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.markdown("### Design Rationale and Best Practices") explanation = generate_response(f"Provide a comprehensive analysis of the web design solution for: {prompt}. Include design principles applied, accessibility considerations, performance optimizations, and how it aligns with current web standards and trends.") st.markdown(explanation) st.markdown("### Alternative Approaches and Future Considerations") alternatives = generate_response(f"Suggest three innovative alternative approaches to the web design challenge: {prompt}. Discuss their pros and cons, potential future web technologies that could enhance the solution, and how these approaches might adapt to emerging web trends.") st.markdown(alternatives) # Fetch and display latest web design trends trends = fetch_latest_web_design_trends() if trends: st.markdown('', unsafe_allow_html=True) # Generate and display a color palette palette = generate_color_palette() st.markdown("### Suggested Color Palette") st.markdown('
', unsafe_allow_html=True) for color in palette: st.markdown(f'
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.markdown("""
Crafted with 🎨💻 by WebGenius AI - Pushing the Boundaries of Web Design
""", unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True)