THEAIMART commited on
Commit
3ed0011
·
verified ·
1 Parent(s): b52dd72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -308
app.py CHANGED
@@ -1,339 +1,155 @@
1
  import streamlit as st
2
- import asyncio
3
- from crewai import Agent, Task, Crew
4
- from langchain_groq import ChatGroq
5
- import time
6
- import os
7
  from dotenv import load_dotenv
8
- import math
 
 
9
 
10
  # Load environment variables
11
  load_dotenv()
 
12
 
13
- # Get API key from environment variable
14
- GROQ_API_KEY = os.getenv("GROQ_API_KEY")
15
-
16
- if not GROQ_API_KEY:
17
- st.error("GROQ API key not found. Please set the GROQ_API_KEY environment variable.")
18
  st.stop()
19
 
20
- # Page configuration
21
  st.set_page_config(page_title="NeuraNexus: AI-Powered ML Assistant", page_icon="🧠", layout="wide")
22
 
23
- # Custom CSS for an advanced, animated, and mobile-responsive UI
 
 
24
  st.markdown("""
25
  <style>
26
- @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700&family=Roboto:wght@300;400;500;700&display=swap');
27
-
28
- :root {
29
- --primary: #4A90E2;
30
- --secondary: #50E3C2;
31
- --tertiary: #FF6B6B;
32
- --bg-dark: #0F1C2E;
33
- --text-light: #FFFFFF;
34
- --text-dark: #333333;
35
- --accent: #E94E77;
36
- }
37
-
38
- body {
39
- background-color: var(--bg-dark);
40
- color: var(--text-light);
41
- font-family: 'Roboto', sans-serif;
42
- line-height: 1.6;
43
- background-image:
44
- radial-gradient(circle at 10% 20%, rgba(74, 144, 226, 0.2) 0%, rgba(74, 144, 226, 0) 40%),
45
- radial-gradient(circle at 90% 80%, rgba(80, 227, 194, 0.2) 0%, rgba(80, 227, 194, 0) 40%),
46
- linear-gradient(to bottom, var(--bg-dark), #1A2B3C);
47
- background-attachment: fixed;
48
- }
49
-
50
- .stApp {
51
- background: rgba(15, 28, 46, 0.85);
52
- border-radius: 15px;
53
- padding: 2rem;
54
- margin-top: 30px;
55
- box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
56
- backdrop-filter: blur(4px);
57
- -webkit-backdrop-filter: blur(4px);
58
- border: 1px solid rgba(255, 255, 255, 0.18);
59
- }
60
-
61
- h1 {
62
- font-family: 'Orbitron', sans-serif;
63
- color: #FF6B6B;
64
- font-weight: 700;
65
- text-transform: uppercase;
66
- letter-spacing: 2px;
67
- text-align: center;
68
- font-size: 2.5em;
69
- margin-bottom: 30px;
70
- text-shadow: 0 0 10px rgba(255, 107, 107, 0.7);
71
- }
72
-
73
- h3 {
74
- font-family: 'Orbitron', sans-serif;
75
- color: var(--secondary);
76
- font-weight: 500;
77
- text-align: center;
78
- margin-bottom: 20px;
79
- font-size: 1.2em;
80
- }
81
-
82
- .stTextInput > div > div > input,
83
- .stTextArea > div > div > textarea {
84
- background-color: rgba(255, 255, 255, 0.05);
85
- color: var(--text-light);
86
- border: 1px solid var(--primary);
87
- border-radius: 10px;
88
- padding: 15px;
89
- transition: all 0.3s ease;
90
- }
91
-
92
- .stTextInput > div > div > input:focus,
93
- .stTextArea > div > div > textarea:focus {
94
- box-shadow: 0 0 15px var(--primary);
95
- border-color: var(--secondary);
96
- }
97
-
98
- .stButton > button {
99
- background: linear-gradient(45deg, var(--primary), var(--accent));
100
- color: var(--text-light);
101
- font-weight: 600;
102
- border: none;
103
- border-radius: 30px;
104
- padding: 0.75rem 2rem;
105
- text-transform: uppercase;
106
- letter-spacing: 1px;
107
- transition: all 0.3s ease;
108
- box-shadow: 0 4px 15px rgba(74, 144, 226, 0.3);
109
- position: relative;
110
- overflow: hidden;
111
- display: block;
112
- margin: 30px auto;
113
- width: 200px;
114
- }
115
-
116
- .stButton > button:hover {
117
- background: linear-gradient(45deg, var(--accent), var(--primary));
118
- box-shadow: 0 6px 20px rgba(74, 144, 226, 0.4);
119
- transform: translateY(-2px);
120
- }
121
-
122
- .stButton > button::after {
123
- content: '';
124
- position: absolute;
125
- top: -50%;
126
- left: -50%;
127
- width: 200%;
128
- height: 200%;
129
- background: linear-gradient(to bottom right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.13) 77%, rgba(255, 255, 255, 0.5) 92%, rgba(255, 255, 255, 0.0) 100%);
130
- transform: rotate(-45deg);
131
- opacity: 0;
132
- transition: opacity 0.3s ease;
133
- }
134
-
135
- .stButton > button:hover::after {
136
- opacity: 1;
137
- animation: shine 1.5s ease-out infinite;
138
- }
139
-
140
- @keyframes shine {
141
- to {
142
- left: 120%;
143
- top: 100%;
144
- }
145
- }
146
-
147
- .result-container {
148
- background: rgba(255, 255, 255, 0.05);
149
- border: 1px solid rgba(74, 144, 226, 0.2);
150
- border-radius: 15px;
151
- padding: 20px;
152
- margin-top: 30px;
153
- color: var(--text-light);
154
- box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
155
- backdrop-filter: blur(10px);
156
- -webkit-backdrop-filter: blur(10px);
157
- transition: all 0.3s ease;
158
- }
159
-
160
- .result-container:hover {
161
- box-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.3);
162
- transform: translateY(-5px);
163
- }
164
-
165
- /* Neural network animation */
166
- .neural-network {
167
- position: fixed;
168
- top: 0;
169
- left: 0;
170
- width: 100%;
171
- height: 100%;
172
- z-index: -1;
173
- overflow: hidden;
174
- pointer-events: none;
175
- }
176
-
177
- .neuron {
178
- position: absolute;
179
- background-color: var(--accent);
180
- border-radius: 50%;
181
- opacity: 0.5;
182
- animation: pulse 4s infinite alternate;
183
- }
184
-
185
- @keyframes pulse {
186
- 0% { transform: scale(1); opacity: 0.5; }
187
- 100% { transform: scale(1.5); opacity: 0.8; }
188
- }
189
-
190
- .synapse {
191
- position: absolute;
192
- background-color: var(--secondary);
193
- height: 1px;
194
- animation: synapseFlash 3s infinite linear;
195
- }
196
-
197
- @keyframes synapseFlash {
198
- 0% { opacity: 0; }
199
- 50% { opacity: 1; }
200
- 100% { opacity: 0; }
201
- }
202
-
203
- .glow {
204
- text-shadow: 0 0 10px var(--primary), 0 0 20px var(--primary), 0 0 30px var(--primary);
205
- animation: textPulse 2s infinite alternate;
206
- }
207
-
208
- @keyframes textPulse {
209
- 0% { text-shadow: 0 0 10px var(--primary), 0 0 20px var(--primary), 0 0 30px var(--primary); }
210
- 100% { text-shadow: 0 0 15px var(--primary), 0 0 25px var(--primary), 0 0 35px var(--primary); }
211
- }
212
-
213
- /* By Theaimart text */
214
- .by-theaimart {
215
- text-align: center;
216
- font-size: 33px;
217
- color: var(--secondary);
218
- margin-top: 20px;
219
- opacity: 0.8;
220
- transition: opacity 0.3s ease;
221
- font-weight: bold;
222
- }
223
-
224
- .by-theaimart:hover {
225
- opacity: 1;
226
- }
227
-
228
- /* Mobile responsiveness */
229
- @media (max-width: 768px) {
230
- h1 {
231
- font-size: 2em;
232
- }
233
-
234
- h3 {
235
- font-size: 1em;
236
- }
237
-
238
- .stButton > button {
239
- width: 100%;
240
- max-width: 200px;
241
- }
242
-
243
- .result-container {
244
- padding: 15px;
245
- }
246
- }
247
  </style>
248
 
 
249
  <div class="neural-network" id="neuralNetwork"></div>
250
-
251
  <script>
252
- function createNeuralNetwork() {
253
- const container = document.getElementById('neuralNetwork');
254
- const numNeurons = 20;
255
- const numSynapses = 30;
256
-
257
- for (let i = 0; i < numNeurons; i++) {
258
- const neuron = document.createElement('div');
259
- neuron.classList.add('neuron');
260
- neuron.style.left = `${Math.random() * 100}%`;
261
- neuron.style.top = `${Math.random() * 100}%`;
262
- neuron.style.width = `${Math.random() * 10 + 5}px`;
263
- neuron.style.height = neuron.style.width;
264
- container.appendChild(neuron);
265
- }
266
-
267
- for (let i = 0; i < numSynapses; i++) {
268
- const synapse = document.createElement('div');
269
- synapse.classList.add('synapse');
270
- synapse.style.left = `${Math.random() * 100}%`;
271
- synapse.style.top = `${Math.random() * 100}%`;
272
- synapse.style.width = `${Math.random() * 200 + 50}px`;
273
- synapse.style.transform = `rotate(${Math.random() * 360}deg)`;
274
- container.appendChild(synapse);
275
- }
276
- }
277
-
278
- document.addEventListener('DOMContentLoaded', createNeuralNetwork);
279
  </script>
280
  """, unsafe_allow_html=True)
281
 
282
- # App title with glow effect
 
 
283
  st.markdown('<h1 class="glow">NeuraNexus: AI-Powered ML Assistant</h1>', unsafe_allow_html=True)
 
284
 
285
- # Main content
286
- st.markdown('<h3>Describe your ML challenge, and let NeuraNexus craft an innovative solution.</h3>', unsafe_allow_html=True)
287
  problem_description = st.text_area("", height=150, placeholder="Enter your ML challenge here...")
 
288
 
289
- # Centered Synthesize button
290
- analyze_button = st.button("SYNTHESIZE", key="analyze_button")
291
-
292
- # Initialize session state
293
  if 'analysis_result' not in st.session_state:
294
  st.session_state.analysis_result = ""
295
 
 
 
 
296
  if analyze_button:
297
- if problem_description:
 
 
298
  with st.spinner("NeuraNexus is synthesizing your solution..."):
299
- llm = ChatGroq(
300
- temperature=0,
301
- groq_api_key=GROQ_API_KEY,
302
- model_name="llama-3.1-8b-instant"
303
- )
304
-
305
- agent = Agent(
306
- role="NeuraNexus - Advanced ML Solution Architect",
307
- goal="Design and explain cutting-edge ML solutions",
308
- backstory="You are NeuraNexus, a state-of-the-art AI specialized in crafting innovative machine learning solutions.",
309
- verbose=True,
310
- allow_delegation=False,
311
- llm=llm,
312
- )
313
-
314
- task = Task(
315
- description=f"Analyze the following ML challenge and provide a detailed solution strategy: {problem_description}",
316
- expected_output="A comprehensive analysis and innovative solution strategy for the given ML challenge.",
317
- agent=agent,
318
- )
319
-
320
- crew = Crew(
321
- agents=[agent],
322
- tasks=[task],
323
- verbose=False
324
- )
325
-
326
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  result = crew.kickoff()
328
  st.session_state.analysis_result = str(result)
329
- except Exception as e:
330
- st.session_state.analysis_result = f"An error occurred during analysis: {str(e)}"
331
 
332
- st.success("Synthesis complete!")
333
- else:
334
- st.warning("Please describe your ML challenge before synthesizing.")
335
 
336
- # Display analysis result
 
 
337
  if st.session_state.analysis_result:
338
  st.markdown("### NeuraNexus Synthesis Result")
339
  st.markdown(f"""
@@ -342,14 +158,10 @@ if st.session_state.analysis_result:
342
  </div>
343
  """, unsafe_allow_html=True)
344
 
345
- # By Theaimart text
346
  st.markdown('<p class="by-theaimart">By Theaimart</p>', unsafe_allow_html=True)
347
 
348
- # Main function to run the Streamlit app
349
  def main():
350
- # The main content of the app is already defined above
351
- # This function can be used to add any additional logic or structure if needed
352
  pass
353
 
354
  if __name__ == "__main__":
355
- main()
 
1
  import streamlit as st
 
 
 
 
 
2
  from dotenv import load_dotenv
3
+ import os
4
+ from crewai import Agent, Task, Crew
5
+ from langchain_google_genai import ChatGoogleGenerativeAI
6
 
7
  # Load environment variables
8
  load_dotenv()
9
+ GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
10
 
11
+ # API key validation
12
+ if not GOOGLE_API_KEY:
13
+ st.error("Google Gemini API key not found. Please set it in the .env file.")
 
 
14
  st.stop()
15
 
16
+ # Streamlit config
17
  st.set_page_config(page_title="NeuraNexus: AI-Powered ML Assistant", page_icon="🧠", layout="wide")
18
 
19
+ # ==========================
20
+ # CSS & Animation
21
+ # ==========================
22
  st.markdown("""
23
  <style>
24
+ /* (Only showing part of the long CSS here to avoid repetition. Replace with your full custom CSS/JS from the previous version) */
25
+
26
+ body {
27
+ background-color: #0F1C2E;
28
+ color: #FFFFFF;
29
+ font-family: 'Roboto', sans-serif;
30
+ }
31
+
32
+ h1 {
33
+ font-family: 'Orbitron', sans-serif;
34
+ color: #FF6B6B;
35
+ text-align: center;
36
+ font-size: 2.5em;
37
+ text-shadow: 0 0 10px rgba(255, 107, 107, 0.7);
38
+ }
39
+
40
+ .result-container {
41
+ background: rgba(255, 255, 255, 0.05);
42
+ border: 1px solid rgba(74, 144, 226, 0.2);
43
+ border-radius: 15px;
44
+ padding: 20px;
45
+ margin-top: 30px;
46
+ color: #FFFFFF;
47
+ box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
48
+ backdrop-filter: blur(10px);
49
+ }
50
+
51
+ .by-theaimart {
52
+ text-align: center;
53
+ font-size: 20px;
54
+ color: #50E3C2;
55
+ margin-top: 20px;
56
+ font-weight: bold;
57
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  </style>
59
 
60
+ <!-- Optional neural animation background -->
61
  <div class="neural-network" id="neuralNetwork"></div>
 
62
  <script>
63
+ function createNeuralNetwork() {
64
+ const container = document.getElementById('neuralNetwork');
65
+ const numNeurons = 20;
66
+ const numSynapses = 30;
67
+ for (let i = 0; i < numNeurons; i++) {
68
+ const neuron = document.createElement('div');
69
+ neuron.classList.add('neuron');
70
+ neuron.style.left = `${Math.random() * 100}%`;
71
+ neuron.style.top = `${Math.random() * 100}%`;
72
+ neuron.style.width = `${Math.random() * 10 + 5}px`;
73
+ neuron.style.height = neuron.style.width;
74
+ container.appendChild(neuron);
75
+ }
76
+ for (let i = 0; i < numSynapses; i++) {
77
+ const synapse = document.createElement('div');
78
+ synapse.classList.add('synapse');
79
+ synapse.style.left = `${Math.random() * 100}%`;
80
+ synapse.style.top = `${Math.random() * 100}%`;
81
+ synapse.style.width = `${Math.random() * 200 + 50}px`;
82
+ synapse.style.transform = `rotate(${Math.random() * 360}deg)`;
83
+ container.appendChild(synapse);
84
+ }
85
+ }
86
+ document.addEventListener('DOMContentLoaded', createNeuralNetwork);
 
 
 
87
  </script>
88
  """, unsafe_allow_html=True)
89
 
90
+ # ==========================
91
+ # UI
92
+ # ==========================
93
  st.markdown('<h1 class="glow">NeuraNexus: AI-Powered ML Assistant</h1>', unsafe_allow_html=True)
94
+ st.markdown('<h3 style="text-align:center;">Describe your ML challenge, and let NeuraNexus craft an innovative solution.</h3>', unsafe_allow_html=True)
95
 
 
 
96
  problem_description = st.text_area("", height=150, placeholder="Enter your ML challenge here...")
97
+ analyze_button = st.button("SYNTHESIZE")
98
 
 
 
 
 
99
  if 'analysis_result' not in st.session_state:
100
  st.session_state.analysis_result = ""
101
 
102
+ # ==========================
103
+ # Handle Analysis
104
+ # ==========================
105
  if analyze_button:
106
+ if not problem_description:
107
+ st.warning("Please describe your ML challenge before synthesizing.")
108
+ else:
109
  with st.spinner("NeuraNexus is synthesizing your solution..."):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  try:
111
+ # Gemini LLM via LangChain
112
+ llm = ChatGoogleGenerativeAI(
113
+ model="gemini-pro",
114
+ google_api_key=GOOGLE_API_KEY,
115
+ temperature=0.2
116
+ )
117
+
118
+ # Define Agent
119
+ agent = Agent(
120
+ role="NeuraNexus - ML Architect",
121
+ goal="Design innovative ML strategies",
122
+ backstory="You are an advanced AI agent trained in modern and futuristic machine learning problem-solving.",
123
+ verbose=True,
124
+ allow_delegation=False,
125
+ llm=llm
126
+ )
127
+
128
+ # Define Task
129
+ task = Task(
130
+ description=f"Analyze the following ML challenge and provide a detailed solution strategy: {problem_description}",
131
+ expected_output="An innovative, clear, and actionable ML solution strategy.",
132
+ agent=agent
133
+ )
134
+
135
+ # Crew
136
+ crew = Crew(
137
+ agents=[agent],
138
+ tasks=[task],
139
+ verbose=False
140
+ )
141
+
142
  result = crew.kickoff()
143
  st.session_state.analysis_result = str(result)
144
+ st.success("Synthesis complete!")
 
145
 
146
+ except Exception as e:
147
+ st.session_state.analysis_result = f"❌ Error: {str(e)}"
148
+ st.error("Gemini synthesis failed.")
149
 
150
+ # ==========================
151
+ # Display Output
152
+ # ==========================
153
  if st.session_state.analysis_result:
154
  st.markdown("### NeuraNexus Synthesis Result")
155
  st.markdown(f"""
 
158
  </div>
159
  """, unsafe_allow_html=True)
160
 
 
161
  st.markdown('<p class="by-theaimart">By Theaimart</p>', unsafe_allow_html=True)
162
 
 
163
  def main():
 
 
164
  pass
165
 
166
  if __name__ == "__main__":
167
+ main()