Artificial-superintelligence commited on
Commit
0b3cd55
·
verified ·
1 Parent(s): cba9efc

Update app.py

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