Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355import streamlit as stimport asynciofrom crewai import Agent, Task, Crewfrom langchain_groq import ChatGroqimport timeimport osfrom dotenv import load_dotenvimport math
# Load environment variablesload_dotenv()
# Get API key from environment variableGROQ_API_KEY = os.getenv("GROQ_API_KEY")
if not GROQ_API_KEY: st.error("GROQ API key not found. Please set the GROQ_API_KEY environment variable.") st.stop()
# Page configurationst.set_page_config(page_title="NeuraNexus: AI-Powered ML Assistant", page_icon="🧠", layout="wide")
# Custom CSS for an advanced, animated, and mobile-responsive UIst.markdown("""<style> @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700&family=Roboto:wght@300;400;500;700&display=swap');
:root { --primary: #4A90E2; --secondary: #50E3C2; --tertiary: #FF6B6B; --bg-dark: #0F1C2E; --text-light: #FFFFFF; --text-dark: #333333; --accent: #E94E77; }
body { background-color: var(--bg-dark); color: var(--text-light); font-family: 'Roboto', sans-serif; line-height: 1.6; background-image: radial-gradient(circle at 10% 20%, rgba(74, 144, 226, 0.2) 0%, rgba(74, 144, 226, 0) 40%), radial-gradient(circle at 90% 80%, rgba(80, 227, 194, 0.2) 0%, rgba(80, 227, 194, 0) 40%), linear-gradient(to bottom, var(--bg-dark), #1A2B3C); background-attachment: fixed; }
.stApp { background: rgba(15, 28, 46, 0.85); border-radius: 15px; padding: 2rem; margin-top: 30px; box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); border: 1px solid rgba(255, 255, 255, 0.18); }
h1 { font-family: 'Orbitron', sans-serif; color: #FF6B6B; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; text-align: center; font-size: 2.5em; margin-bottom: 30px; text-shadow: 0 0 10px rgba(255, 107, 107, 0.7); }
h3 { font-family: 'Orbitron', sans-serif; color: var(--secondary); font-weight: 500; text-align: center; margin-bottom: 20px; font-size: 1.2em; }
.stTextInput > div > div > input, .stTextArea > div > div > textarea { background-color: rgba(255, 255, 255, 0.05); color: var(--text-light); border: 1px solid var(--primary); border-radius: 10px; padding: 15px; transition: all 0.3s ease; }
.stTextInput > div > div > input:focus, .stTextArea > div > div > textarea:focus { box-shadow: 0 0 15px var(--primary); border-color: var(--secondary); }
.stButton > button { background: linear-gradient(45deg, var(--primary), var(--accent)); color: var(--text-light); font-weight: 600; border: none; border-radius: 30px; padding: 0.75rem 2rem; text-transform: uppercase; letter-spacing: 1px; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(74, 144, 226, 0.3); position: relative; overflow: hidden; display: block; margin: 30px auto; width: 200px; }
.stButton > button:hover { background: linear-gradient(45deg, var(--accent), var(--primary)); box-shadow: 0 6px 20px rgba(74, 144, 226, 0.4); transform: translateY(-2px); }
.stButton > button::after { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; 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%); transform: rotate(-45deg); opacity: 0; transition: opacity 0.3s ease; }
.stButton > button:hover::after { opacity: 1; animation: shine 1.5s ease-out infinite; }
@keyframes shine { to { left: 120%; top: 100%; } }
.result-container { background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(74, 144, 226, 0.2); border-radius: 15px; padding: 20px; margin-top: 30px; color: var(--text-light); box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: all 0.3s ease; }
.result-container:hover { box-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.3); transform: translateY(-5px); }
/* Neural network animation */ .neural-network { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; overflow: hidden; pointer-events: none; }
.neuron { position: absolute; background-color: var(--accent); border-radius: 50%; opacity: 0.5; animation: pulse 4s infinite alternate; }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.5; } 100% { transform: scale(1.5); opacity: 0.8; } }
.synapse { position: absolute; background-color: var(--secondary); height: 1px; animation: synapseFlash 3s infinite linear; }
@keyframes synapseFlash { 0% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: 0; } }
.glow { text-shadow: 0 0 10px var(--primary), 0 0 20px var(--primary), 0 0 30px var(--primary); animation: textPulse 2s infinite alternate; }
@keyframes textPulse { 0% { text-shadow: 0 0 10px var(--primary), 0 0 20px var(--primary), 0 0 30px var(--primary); } 100% { text-shadow: 0 0 15px var(--primary), 0 0 25px var(--primary), 0 0 35px var(--primary); } }
/* By Theaimart text */ .by-theaimart { text-align: center; font-size: 33px; color: var(--secondary); margin-top: 20px; opacity: 0.8; transition: opacity 0.3s ease; font-weight: bold; }
.by-theaimart:hover { opacity: 1; }
/* Mobile responsiveness */ @media (max-width: 768px) { h1 { font-size: 2em; }
h3 { font-size: 1em; }
.stButton > button { width: 100%; max-width: 200px; }
.result-container { padding: 15px; } }</style>
<div class="neural-network" id="neuralNetwork"></div>
<script> function createNeuralNetwork() { const container = document.getElementById('neuralNetwork'); const numNeurons = 20; const numSynapses = 30;
for (let i = 0; i < numNeurons; i++) { const neuron = document.createElement('div'); neuron.classList.add('neuron'); neuron.style.left = `${Math.random() * 100}%`; neuron.style.top = `${Math.random() * 100}%`; neuron.style.width = `${Math.random() * 10 + 5}px`; neuron.style.height = neuron.style.width; container.appendChild(neuron); }
for (let i = 0; i < numSynapses; i++) { const synapse = document.createElement('div'); synapse.classList.add('synapse'); synapse.style.left = `${Math.random() * 100}%`; synapse.style.top = `${Math.random() * 100}%`; synapse.style.width = `${Math.random() * 200 + 50}px`; synapse.style.transform = `rotate(${Math.random() * 360}deg)`; container.appendChild(synapse); } }
document.addEventListener('DOMContentLoaded', createNeuralNetwork);</script>""", unsafe_allow_html=True)
# App title with glow effectst.markdown('<h1 class="glow">NeuraNexus: AI-Powered ML Assistant</h1>', unsafe_allow_html=True)
# Main contentst.markdown('<h3>Describe your ML challenge, and let NeuraNexus craft an innovative solution.</h3>', unsafe_allow_html=True)problem_description = st.text_area("", height=150, placeholder="Enter your ML challenge here...")
# Centered Synthesize buttonanalyze_button = st.button("SYNTHESIZE", key="analyze_button")
# Initialize session stateif 'analysis_result' not in st.session_state: st.session_state.analysis_result = ""
if analyze_button: if problem_description: with st.spinner("NeuraNexus is synthesizing your solution..."): llm = ChatGroq( temperature=0, groq_api_key=GROQ_API_KEY, model_name="mixtral-8x7b-32768" )
agent = Agent( role="NeuraNexus - Advanced ML Solution Architect", goal="Design and explain cutting-edge ML solutions", backstory="You are NeuraNexus, a state-of-the-art AI specialized in crafting innovative machine learning solutions.", verbose=True, allow_delegation=False, llm=llm, )
task = Task( description=f"Analyze the following ML challenge and provide a detailed solution strategy: {problem_description}", expected_output="A comprehensive analysis and innovative solution strategy for the given ML challenge.", agent=agent, )
crew = Crew( agents=[agent], tasks=[task], verbose=False )
try: result = crew.kickoff() st.session_state.analysis_result = str(result) except Exception as e: st.session_state.analysis_result = f"An error occurred during analysis: {str(e)}"
st.success("Synthesis complete!") else: st.warning("Please describe your ML challenge before synthesizing.")
# Display analysis resultif st.session_state.analysis_result: st.markdown("### NeuraNexus Synthesis Result") st.markdown(f""" <div class="result-container"> {st.session_state.analysis_result} </div> """, unsafe_allow_html=True)
# By Theaimart textst.markdown('<p class="by-theaimart">By Theaimart</p>', unsafe_allow_html=True)
# Main function to run the Streamlit appdef main(): # The main content of the app is already defined above # This function can be used to add any additional logic or structure if needed pass
if __name__ == "__main__": main()app.pyAdded+355