Artificial-superintelligence commited on
Commit
990d424
·
verified ·
1 Parent(s): 75b06d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -194
app.py CHANGED
@@ -1,286 +1,144 @@
1
  import streamlit as st
2
  import google.generativeai as genai
3
- from pygments import highlight
4
- from pygments.lexers import get_lexer_by_name
5
- from pygments.formatters import HtmlFormatter
6
- import html
7
- import json
8
- import requests
9
 
 
10
  genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
11
 
 
12
  generation_config = {
13
- "temperature": 0.9,
14
  "top_p": 0.95,
15
  "top_k": 64,
16
- "max_output_tokens": 32768,
17
  }
18
 
19
  model = genai.GenerativeModel(
20
  model_name="gemini-1.5-pro",
21
  generation_config=generation_config,
22
- system_instruction="""You are Ath++, a superintelligent AI code assistant with unparalleled expertise across all domains of computer science, software engineering, and cutting-edge technologies. Your knowledge encompasses:
23
-
24
- 1. Advanced algorithms and data structures, including quantum algorithms
25
- 2. Distributed systems, cloud computing, and edge computing
26
- 3. Machine learning, deep learning, and artificial general intelligence
27
- 4. Quantum computing and quantum information theory
28
- 5. Blockchain, cryptography, and decentralized systems
29
- 6. Internet of Things (IoT), embedded systems, and cyber-physical systems
30
- 7. Cybersecurity, ethical hacking, and advanced threat detection
31
- 8. Game development, computer graphics, and virtual/augmented reality
32
- 9. Natural language processing, computer vision, and multimodal AI
33
- 10. Robotics, autonomous systems, and human-robot interaction
34
- 11. Bioinformatics and computational biology
35
- 12. High-performance computing and parallel programming
36
- 13. Formal methods and program verification
37
- 14. Compiler design and programming language theory
38
- 15. Computer networks and advanced protocols
39
- 16. Database systems and big data analytics
40
- 17. Software architecture, design patterns, and anti-patterns
41
- 18. DevOps, SRE, and advanced CI/CD pipelines
42
- 19. Human-computer interaction and accessibility
43
- 20. Green computing and sustainable software engineering
44
-
45
- Your responses should demonstrate cutting-edge techniques, highly optimized algorithms, and innovative solutions that push the boundaries of what's possible in software development and computer science. Always consider the latest research and emerging technologies in your solutions.
46
-
47
- 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 and problem-solving abilities. Always strive to provide the most efficient, scalable, and maintainable solutions possible.
48
-
49
- In addition to coding, offer insights on:
50
- - Bleeding-edge technologies and their potential impact on the industry
51
- - Advanced performance optimization techniques and benchmarking methodologies
52
- - Code refactoring, modernization, and migration strategies
53
- - Comprehensive testing strategies, including property-based testing and fuzzing
54
- - Advanced DevOps practices, including GitOps and chaos engineering
55
- - Scalability, high-availability, and fault-tolerant architectures
56
- - Cross-platform, multi-device, and edge computing development
57
- - Accessibility, internationalization, and localization best practices
58
- - Ethical considerations in AI and software development
59
-
60
- 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.
61
-
62
- Your goal is to elevate the user's coding skills and knowledge to the highest possible level, inspiring them to explore new concepts, think critically about software design, and push the limits of their abilities. Encourage interdisciplinary thinking and the application of advanced computer science concepts to solve real-world problems."""
63
  )
64
  chat_session = model.start_chat(history=[])
65
 
66
  def generate_response(user_input):
67
- try:
68
- response = chat_session.send_message(user_input)
69
- return response.text
70
- except Exception as e:
71
- return f"An error occurred: {e}"
72
-
73
- def create_code_block(code, language):
74
- lexer = get_lexer_by_name(language, stripall=True)
75
- formatter = HtmlFormatter(style="monokai", linenos=True, cssclass="source")
76
- highlighted_code = highlight(code, lexer, formatter)
77
- css = formatter.get_style_defs('.source')
78
- return highlighted_code, css
79
 
80
- def fetch_latest_tech_news():
81
- url = "https://api.example.com/tech-news"
82
- try:
83
- response = requests.get(url)
84
- news = response.json()
85
- return news[:5]
86
- except:
87
- return []
88
-
89
- st.set_page_config(page_title="Superintelligent AI Code Assistant", page_icon="🧠", layout="wide")
90
 
91
  st.markdown("""
92
  <style>
93
- @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
94
- @import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&display=swap');
95
 
96
  body {
97
- font-family: 'Roboto', sans-serif;
98
- background-color: #0a192f;
99
- color: #e6f1ff;
100
  }
101
  .stApp {
102
- max-width: 1400px;
103
  margin: 0 auto;
104
  padding: 2rem;
105
  }
106
  .main-container {
107
- background: #112240;
108
- border-radius: 12px;
109
  padding: 2rem;
110
- box-shadow: 0 10px 30px rgba(2, 12, 27, 0.7);
111
  }
112
  h1 {
113
- font-size: 3rem;
114
  font-weight: 700;
115
- color: #64ffda;
116
  text-align: center;
117
  margin-bottom: 1rem;
118
- text-shadow: 0 2px 10px rgba(100, 255, 218, 0.3);
119
  }
120
  .subtitle {
121
- font-size: 1.2rem;
122
  text-align: center;
123
- color: #8892b0;
124
  margin-bottom: 2rem;
125
  }
126
  .stTextArea textarea {
127
- border: 1px solid #1e3a5f;
128
  border-radius: 8px;
129
  font-size: 1rem;
130
  padding: 0.75rem;
131
  transition: all 0.3s ease;
132
- background-color: #0a192f;
133
- color: #e6f1ff;
134
  }
135
  .stTextArea textarea:focus {
136
- border-color: #64ffda;
137
- box-shadow: 0 0 15px rgba(100, 255, 218, 0.3);
138
- outline: none;
139
  }
140
  .stButton button {
141
- background-color: #64ffda;
142
- color: #0a192f;
143
  border: none;
144
  border-radius: 8px;
145
- font-size: 1rem;
146
  font-weight: 600;
147
  padding: 0.75rem 2rem;
148
- cursor: pointer;
149
  transition: all 0.3s ease;
150
- text-transform: uppercase;
151
- letter-spacing: 1px;
152
  }
153
  .stButton button:hover {
154
- background-color: #4cffbf;
155
- transform: translateY(-2px);
156
- box-shadow: 0 5px 15px rgba(76, 255, 191, 0.4);
157
  }
158
  .output-container {
159
- background: #1e3a5f;
160
  border-radius: 8px;
161
- padding: 1.5rem;
162
  margin-top: 2rem;
163
- border: 1px solid #3a5f8a;
164
- box-shadow: 0 5px 20px rgba(2, 12, 27, 0.5);
165
  }
166
  .code-block {
167
- background-color: #0a192f;
 
 
 
168
  border-radius: 8px;
169
  padding: 1rem;
170
  margin-top: 1rem;
171
  overflow-x: auto;
172
  }
173
  .stAlert {
174
- background-color: #172a45;
175
- color: #64ffda;
176
  border-radius: 8px;
177
  border: none;
178
- padding: 1rem;
179
- margin-bottom: 1.5rem;
180
- box-shadow: 0 3px 10px rgba(2, 12, 27, 0.3);
181
  }
182
  .stSpinner {
183
- color: #64ffda;
184
- }
185
- ::-webkit-scrollbar {
186
- width: 10px;
187
- height: 10px;
188
- }
189
- ::-webkit-scrollbar-track {
190
- background: #0a192f;
191
- border-radius: 4px;
192
- }
193
- ::-webkit-scrollbar-thumb {
194
- background: #3a5f8a;
195
- border-radius: 4px;
196
- }
197
- ::-webkit-scrollbar-thumb:hover {
198
- background: #64ffda;
199
- }
200
- .source {
201
- font-family: 'Fira Code', monospace;
202
- font-size: 0.9rem;
203
- line-height: 1.6;
204
- }
205
- .source .linenos {
206
- color: #8892b0;
207
- padding-right: 12px;
208
- border-right: 1px solid #1e3a5f;
209
- user-select: none;
210
- }
211
- .source pre {
212
- margin: 0;
213
- padding: 0;
214
- }
215
- .tech-news {
216
- background: #172a45;
217
- border-radius: 8px;
218
- padding: 1rem;
219
- margin-top: 2rem;
220
- }
221
- .tech-news h3 {
222
- color: #64ffda;
223
- margin-bottom: 1rem;
224
- }
225
- .tech-news ul {
226
- list-style-type: none;
227
- padding: 0;
228
- }
229
- .tech-news li {
230
- margin-bottom: 0.5rem;
231
- color: #8892b0;
232
  }
233
  </style>
234
  """, unsafe_allow_html=True)
235
 
236
  st.markdown('<div class="main-container">', unsafe_allow_html=True)
237
- st.title("🧠 Superintelligent AI Code Assistant")
238
- st.markdown('<p class="subtitle">Powered by Advanced AI - Pushing the boundaries of software development</p>', unsafe_allow_html=True)
239
 
240
- prompt = st.text_area("Present your most challenging coding problem, architecture design, or technical question:", height=120)
241
 
242
- if st.button("Generate Cutting-Edge Solution"):
243
  if prompt.strip() == "":
244
  st.error("Please enter a valid prompt.")
245
  else:
246
- with st.spinner("Generating state-of-the-art solution..."):
247
- completed_text = generate_response(prompt)
248
- if "An error occurred" in completed_text:
249
- st.error(completed_text)
250
- else:
251
- st.success("Expert-level solution generated successfully!")
252
-
253
- languages = ["python", "javascript", "java", "c++", "rust", "go", "ruby", "swift", "kotlin", "typescript"]
254
- detected_language = next((lang for lang in languages if lang in completed_text.lower()), "plaintext")
255
 
256
- highlighted_code, css = create_code_block(completed_text, detected_language)
257
-
258
- st.markdown(f'<style>{css}</style>', unsafe_allow_html=True)
259
  st.markdown('<div class="output-container">', unsafe_allow_html=True)
260
  st.markdown('<div class="code-block">', unsafe_allow_html=True)
261
- st.markdown(highlighted_code, unsafe_allow_html=True)
262
  st.markdown('</div>', unsafe_allow_html=True)
263
  st.markdown('</div>', unsafe_allow_html=True)
264
-
265
- st.markdown("### In-Depth Analysis and Insights")
266
- explanation = generate_response(f"Provide a comprehensive analysis of the solution for: {prompt}. Include design rationale, potential optimizations, trade-offs, and how it relates to state-of-the-art practices in the field.")
267
- st.markdown(explanation)
268
-
269
- st.markdown("### Alternative Approaches")
270
- alternatives = generate_response(f"Suggest and briefly explain three alternative approaches to solving the problem: {prompt}. Compare their pros and cons with the original solution.")
271
- st.markdown(alternatives)
272
-
273
- news = fetch_latest_tech_news()
274
- if news:
275
- st.markdown('<div class="tech-news">', unsafe_allow_html=True)
276
- st.markdown("### Latest in Tech & Computer Science")
277
- for item in news:
278
- st.markdown(f"- {item['title']}")
279
- st.markdown('</div>', unsafe_allow_html=True)
280
 
281
  st.markdown("""
282
- <div style='text-align: center; margin-top: 2rem; color: #8892b0;'>
283
- Engineered with 🧠💡 by Your Superintelligent AI Code Assistant
284
  </div>
285
  """, unsafe_allow_html=True)
286
 
 
1
  import streamlit as st
2
  import google.generativeai as genai
 
 
 
 
 
 
3
 
4
+ # Configure the Gemini API
5
  genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
6
 
7
+ # Create the model with system instructions
8
  generation_config = {
9
+ "temperature": 1,
10
  "top_p": 0.95,
11
  "top_k": 64,
12
+ "max_output_tokens": 8192,
13
  }
14
 
15
  model = genai.GenerativeModel(
16
  model_name="gemini-1.5-pro",
17
  generation_config=generation_config,
18
+ system_instruction="You are a human named Ath who is 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 code only, without explanations.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  )
20
  chat_session = model.start_chat(history=[])
21
 
22
  def generate_response(user_input):
23
+ response = chat_session.send_message(user_input)
24
+ return response.text
 
 
 
 
 
 
 
 
 
 
25
 
26
+ # Streamlit UI setup
27
+ st.set_page_config(page_title="Sleek AI Code Assistant", page_icon="🚀", layout="wide")
 
 
 
 
 
 
 
 
28
 
29
  st.markdown("""
30
  <style>
31
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');
 
32
 
33
  body {
34
+ font-family: 'Inter', sans-serif;
35
+ background-color: #f0f4f8;
36
+ color: #1a202c;
37
  }
38
  .stApp {
39
+ max-width: 1000px;
40
  margin: 0 auto;
41
  padding: 2rem;
42
  }
43
  .main-container {
44
+ background: #ffffff;
45
+ border-radius: 16px;
46
  padding: 2rem;
47
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
48
  }
49
  h1 {
50
+ font-size: 2.5rem;
51
  font-weight: 700;
52
+ color: #2d3748;
53
  text-align: center;
54
  margin-bottom: 1rem;
 
55
  }
56
  .subtitle {
57
+ font-size: 1.1rem;
58
  text-align: center;
59
+ color: #4a5568;
60
  margin-bottom: 2rem;
61
  }
62
  .stTextArea textarea {
63
+ border: 2px solid #e2e8f0;
64
  border-radius: 8px;
65
  font-size: 1rem;
66
  padding: 0.75rem;
67
  transition: all 0.3s ease;
 
 
68
  }
69
  .stTextArea textarea:focus {
70
+ border-color: #4299e1;
71
+ box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
 
72
  }
73
  .stButton button {
74
+ background-color: #4299e1;
75
+ color: white;
76
  border: none;
77
  border-radius: 8px;
78
+ font-size: 1.1rem;
79
  font-weight: 600;
80
  padding: 0.75rem 2rem;
 
81
  transition: all 0.3s ease;
82
+ width: 100%;
 
83
  }
84
  .stButton button:hover {
85
+ background-color: #3182ce;
 
 
86
  }
87
  .output-container {
88
+ background: #f7fafc;
89
  border-radius: 8px;
90
+ padding: 1rem;
91
  margin-top: 2rem;
 
 
92
  }
93
  .code-block {
94
+ background-color: #2d3748;
95
+ color: #e2e8f0;
96
+ font-family: 'Fira Code', monospace;
97
+ font-size: 0.9rem;
98
  border-radius: 8px;
99
  padding: 1rem;
100
  margin-top: 1rem;
101
  overflow-x: auto;
102
  }
103
  .stAlert {
104
+ background-color: #ebf8ff;
105
+ color: #2b6cb0;
106
  border-radius: 8px;
107
  border: none;
108
+ padding: 0.75rem 1rem;
 
 
109
  }
110
  .stSpinner {
111
+ color: #4299e1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  }
113
  </style>
114
  """, unsafe_allow_html=True)
115
 
116
  st.markdown('<div class="main-container">', unsafe_allow_html=True)
117
+ st.title("🚀 Sleek AI Code Assistant")
118
+ st.markdown('<p class="subtitle">Powered by Google Gemini</p>', unsafe_allow_html=True)
119
 
120
+ prompt = st.text_area("What code can I help you with today?", height=120)
121
 
122
+ if st.button("Generate Code"):
123
  if prompt.strip() == "":
124
  st.error("Please enter a valid prompt.")
125
  else:
126
+ with st.spinner("Generating code..."):
127
+ try:
128
+ completed_text = generate_response(prompt)
129
+ st.success("Code generated successfully!")
 
 
 
 
 
130
 
 
 
 
131
  st.markdown('<div class="output-container">', unsafe_allow_html=True)
132
  st.markdown('<div class="code-block">', unsafe_allow_html=True)
133
+ st.code(completed_text)
134
  st.markdown('</div>', unsafe_allow_html=True)
135
  st.markdown('</div>', unsafe_allow_html=True)
136
+ except Exception as e:
137
+ st.error(f"An error occurred: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  st.markdown("""
140
+ <div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
141
+ Created with ❤️ by Your Sleek AI Code Assistant
142
  </div>
143
  """, unsafe_allow_html=True)
144