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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -98
app.py CHANGED
@@ -1,34 +1,33 @@
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;
@@ -36,18 +35,16 @@ h1 {
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;
@@ -56,110 +53,57 @@ h1 {
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"""
156
  <div class="result-container">
157
- {st.session_state.analysis_result}
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
 
 
1
  import streamlit as st
 
2
  import os
3
+ from dotenv import load_dotenv
4
+ import google.generativeai as genai
5
 
6
  # Load environment variables
7
  load_dotenv()
8
  GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
9
 
10
+ # Validate API Key
11
  if not GOOGLE_API_KEY:
12
+ st.error("Google Gemini API key not found. Please set GOOGLE_API_KEY in your .env file.")
13
  st.stop()
14
 
15
+ # Configure Gemini
16
+ genai.configure(api_key=GOOGLE_API_KEY)
17
+
18
+ # Streamlit page setup
19
  st.set_page_config(page_title="NeuraNexus: AI-Powered ML Assistant", page_icon="🧠", layout="wide")
20
 
21
+ # ==============================
22
+ # Custom CSS (include your full CSS here)
23
+ # ==============================
24
  st.markdown("""
25
  <style>
 
 
26
  body {
27
  background-color: #0F1C2E;
28
+ color: white;
29
  font-family: 'Roboto', sans-serif;
30
  }
 
31
  h1 {
32
  font-family: 'Orbitron', sans-serif;
33
  color: #FF6B6B;
 
35
  font-size: 2.5em;
36
  text-shadow: 0 0 10px rgba(255, 107, 107, 0.7);
37
  }
 
38
  .result-container {
39
  background: rgba(255, 255, 255, 0.05);
40
  border: 1px solid rgba(74, 144, 226, 0.2);
41
  border-radius: 15px;
42
  padding: 20px;
43
  margin-top: 30px;
44
+ color: white;
45
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
46
  backdrop-filter: blur(10px);
47
  }
 
48
  .by-theaimart {
49
  text-align: center;
50
  font-size: 20px;
 
53
  font-weight: bold;
54
  }
55
  </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  """, unsafe_allow_html=True)
57
 
58
+ # ==============================
59
+ # App UI
60
+ # ==============================
61
  st.markdown('<h1 class="glow">NeuraNexus: AI-Powered ML Assistant</h1>', unsafe_allow_html=True)
62
  st.markdown('<h3 style="text-align:center;">Describe your ML challenge, and let NeuraNexus craft an innovative solution.</h3>', unsafe_allow_html=True)
63
 
64
+ # Input from user
65
+ user_prompt = st.text_area("Your ML Challenge", height=150, placeholder="Enter your machine learning challenge here...")
66
 
67
+ if 'response' not in st.session_state:
68
+ st.session_state.response = ""
69
 
70
+ # Generate button
71
+ if st.button("SYNTHESIZE"):
72
+ if not user_prompt.strip():
73
+ st.warning("Please describe your ML challenge first.")
 
 
74
  else:
75
+ with st.spinner("NeuraNexus is thinking..."):
76
  try:
77
+ model = genai.GenerativeModel("gemini-pro")
78
+ chat = model.start_chat()
79
+
80
+ system_prompt = "You are NeuraNexus, an AI specialized in designing innovative and actionable ML strategies. Provide expert-level solutions to the given ML challenge."
81
+
82
+ full_prompt = f"{system_prompt}\n\nUser Problem:\n{user_prompt}"
83
+
84
+ response = chat.send_message(full_prompt)
85
+ st.session_state.response = response.text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  st.success("Synthesis complete!")
87
 
88
  except Exception as e:
89
+ st.session_state.response = f"❌ Error: {e}"
90
  st.error("Gemini synthesis failed.")
91
 
92
+ # ==============================
93
+ # Show result
94
+ # ==============================
95
+ if st.session_state.response:
96
  st.markdown("### NeuraNexus Synthesis Result")
97
  st.markdown(f"""
98
  <div class="result-container">
99
+ {st.session_state.response}
100
  </div>
101
  """, unsafe_allow_html=True)
102
 
103
+ # Footer
104
  st.markdown('<p class="by-theaimart">By Theaimart</p>', unsafe_allow_html=True)
105
 
106
+ # Run wrapper
107
  def main():
108
  pass
109