File size: 12,290 Bytes
f8dbf90
 
921a07f
 
 
 
0b3cd55
 
c8bbe21
f8dbf90
 
 
 
c8bbe21
f8dbf90
0b3cd55
f8dbf90
d40005d
c8bbe21
f8dbf90
 
 
e705807
f8dbf90
c8bbe21
0b3cd55
c8bbe21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b3cd55
c8bbe21
0b3cd55
c8bbe21
0b3cd55
 
c8bbe21
 
 
 
 
 
 
 
0b3cd55
 
 
ea970cd
f8dbf90
cba9efc
f8dbf90
 
a7a2ad9
cba9efc
a7a2ad9
 
 
f8dbf90
921a07f
 
 
 
 
 
 
c8bbe21
 
0b3cd55
 
c8bbe21
 
0b3cd55
 
 
c8bbe21
 
 
 
 
 
 
 
 
f8dbf90
c8bbe21
f8dbf90
cba9efc
 
c8bbe21
cba9efc
 
c8bbe21
 
 
cba9efc
 
0b3cd55
cba9efc
 
 
 
c8bbe21
 
cba9efc
c8bbe21
cba9efc
 
c8bbe21
0b3cd55
c8bbe21
cba9efc
 
c8bbe21
 
 
cba9efc
 
0b3cd55
cba9efc
c8bbe21
cba9efc
 
 
c8bbe21
 
cba9efc
c8bbe21
0b3cd55
c8bbe21
 
cba9efc
 
c8bbe21
 
cba9efc
 
 
c8bbe21
 
cba9efc
c8bbe21
cba9efc
0b3cd55
 
cba9efc
0b3cd55
 
 
cba9efc
 
c8bbe21
cba9efc
c8bbe21
cba9efc
 
c8bbe21
 
0b3cd55
 
c8bbe21
 
cba9efc
 
c8bbe21
 
cba9efc
 
 
 
 
c8bbe21
 
 
cba9efc
 
0b3cd55
c8bbe21
cba9efc
 
c8bbe21
cba9efc
 
 
0b3cd55
 
cba9efc
 
c8bbe21
cba9efc
 
 
c8bbe21
cba9efc
 
 
c8bbe21
cba9efc
 
 
 
0b3cd55
cba9efc
 
c8bbe21
0b3cd55
c8bbe21
cba9efc
 
 
 
 
 
c8bbe21
 
 
 
0b3cd55
 
c8bbe21
 
0b3cd55
 
c8bbe21
0b3cd55
 
 
c8bbe21
0b3cd55
c8bbe21
 
 
 
 
 
 
 
 
 
 
 
0b3cd55
cba9efc
 
83ac817
b479e07
c8bbe21
 
b479e07
c8bbe21
da7ac0b
c8bbe21
d35faf8
921a07f
83ac817
c8bbe21
921a07f
a7a2ad9
 
 
c8bbe21
cba9efc
c8bbe21
 
 
a7a2ad9
0b3cd55
cba9efc
 
 
 
 
 
 
 
c8bbe21
 
cba9efc
ec018dc
c8bbe21
 
0b3cd55
 
c8bbe21
 
 
 
 
 
 
0b3cd55
 
c8bbe21
 
 
 
 
 
 
 
d35faf8
c8bbe21
 
d35faf8
b479e07
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
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,you give code only,you never explain"""
)
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("""
<style>
    @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
    
    body {
        font-family: 'Inter', sans-serif;
        background-color: #f0f4f8;
        color: #1a202c;
    }
    .stApp {
        max-width: 1400px;
        margin: 0 auto;
        padding: 2rem;
    }
    .main-container {
        background: #ffffff;
        border-radius: 16px;
        padding: 2rem;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    }
    h1 {
        font-size: 3.5rem;
        font-weight: 700;
        color: #4a5568;
        text-align: center;
        margin-bottom: 1rem;
        background: linear-gradient(45deg, #3498db, #8e44ad);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    .subtitle {
        font-size: 1.2rem;
        text-align: center;
        color: #718096;
        margin-bottom: 2rem;
    }
    .stTextArea textarea {
        border: 2px solid #e2e8f0;
        border-radius: 12px;
        font-size: 1rem;
        padding: 1rem;
        transition: all 0.3s ease;
        background-color: #f7fafc;
        color: #2d3748;
    }
    .stTextArea textarea:focus {
        border-color: #4299e1;
        box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
        outline: none;
    }
    .stButton button {
        background: linear-gradient(45deg, #3498db, #8e44ad);
        color: #ffffff;
        border: none;
        border-radius: 12px;
        font-size: 1rem;
        font-weight: 600;
        padding: 0.75rem 2rem;
        cursor: pointer;
        transition: all 0.3s ease;
        text-transform: uppercase;
        letter-spacing: 1px;
    }
    .stButton button:hover {
        opacity: 0.9;
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(66, 153, 225, 0.4);
    }
    .output-container {
        background: #f7fafc;
        border-radius: 12px;
        padding: 1.5rem;
        margin-top: 2rem;
        border: 2px solid #e2e8f0;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
    }
    .code-block {
        background-color: #2d3748;
        border-radius: 12px;
        padding: 1rem;
        margin-top: 1rem;
        overflow-x: auto;
    }
    .stAlert {
        background-color: #ebf8ff;
        color: #2b6cb0;
        border-radius: 12px;
        border: none;
        padding: 1rem;
        margin-bottom: 1.5rem;
        box-shadow: 0 3px 10px rgba(43, 108, 176, 0.1);
    }
    .stSpinner {
        color: #3498db;
    }
    /* Custom scrollbar */
    ::-webkit-scrollbar {
        width: 10px;
        height: 10px;
    }
    ::-webkit-scrollbar-track {
        background: #f7fafc;
        border-radius: 4px;
    }
    ::-webkit-scrollbar-thumb {
        background: #cbd5e0;
        border-radius: 4px;
    }
    ::-webkit-scrollbar-thumb:hover {
        background: #a0aec0;
    }
    .source {
        font-family: 'Fira Code', monospace;
        font-size: 0.9rem;
        line-height: 1.6;
    }
    .source .linenos {
        color: #a0aec0;
        padding-right: 12px;
        border-right: 1px solid #4a5568;
        user-select: none;
    }
    .source pre {
        margin: 0;
        padding: 0;
    }
    .web-design-trends {
        background: #ebf8ff;
        border-radius: 12px;
        padding: 1.5rem;
        margin-top: 2rem;
    }
    .web-design-trends h3 {
        color: #2b6cb0;
        margin-bottom: 1rem;
    }
    .web-design-trends ul {
        list-style-type: none;
        padding: 0;
    }
    .web-design-trends li {
        margin-bottom: 0.5rem;
        color: #4a5568;
    }
    .color-palette {
        display: flex;
        justify-content: space-between;
        margin-top: 1rem;
    }
    .color-swatch {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }
</style>
""", unsafe_allow_html=True)

st.markdown('<div class="main-container">', unsafe_allow_html=True)
st.title("🎨 WebGenius AI")
st.markdown('<p class="subtitle">Advanced Web Design Assistant - Crafting the Future of the Web</p>', 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'<style>{css}</style>', unsafe_allow_html=True)
                st.markdown('<div class="output-container">', unsafe_allow_html=True)
                st.markdown('<div class="code-block">', unsafe_allow_html=True)
                st.markdown(highlighted_code, unsafe_allow_html=True)
                st.markdown('</div>', unsafe_allow_html=True)
                st.markdown('</div>', 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('<div class="web-design-trends">', unsafe_allow_html=True)
    st.markdown("### Latest Web Design Trends")
    for trend in trends:
        st.markdown(f"- {trend['title']}")
    st.markdown('</div>', unsafe_allow_html=True)

# Generate and display a color palette
palette = generate_color_palette()
st.markdown("### Suggested Color Palette")
st.markdown('<div class="color-palette">', unsafe_allow_html=True)
for color in palette:
    st.markdown(f'<div class="color-swatch" style="background-color: {color};"></div>', unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)

st.markdown("""
<div style='text-align: center; margin-top: 2rem; color: #718096;'>
    Crafted with πŸŽ¨πŸ’» by WebGenius AI - Pushing the Boundaries of Web Design
</div>
""", unsafe_allow_html=True)

st.markdown('</div>', unsafe_allow_html=True)