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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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="mixtral-8x7b-32768"
|
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"""
|
340 |
+
<div class="result-container">
|
341 |
+
{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()
|