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|
+
import config
|
5 |
+
import json
|
6 |
+
import time
|
7 |
+
from filter import is_solar_related # Import the solar query filter
|
8 |
+
|
9 |
+
# Configure Gemini API
|
10 |
+
genai.configure(api_key=config.API_KEY)
|
11 |
+
|
12 |
+
def get_ai_response(user_input):
|
13 |
+
model = genai.GenerativeModel("gemini-pro") # Using Gemini Pro model
|
14 |
+
response = model.generate_content(user_input)
|
15 |
+
return response.text if hasattr(response, "text") else "Error fetching response"
|
16 |
+
|
17 |
+
# Set page config
|
18 |
+
st.set_page_config(
|
19 |
+
page_title="Solar Industry AI Assistant",
|
20 |
+
page_icon="βοΈ",
|
21 |
+
layout="wide",
|
22 |
+
initial_sidebar_state="expanded"
|
23 |
+
)
|
24 |
+
|
25 |
+
# Custom CSS for enhanced UI
|
26 |
+
st.markdown("""
|
27 |
+
<style>
|
28 |
+
.main-title {
|
29 |
+
font-size: 2.5rem !important;
|
30 |
+
color: #FF9900 !important;
|
31 |
+
text-align: center;
|
32 |
+
margin-bottom: 1rem;
|
33 |
+
text-shadow: 1px 1px 2px #00000030;
|
34 |
+
}
|
35 |
+
.stButton>button {
|
36 |
+
background-color: #FF9900;
|
37 |
+
color: white;
|
38 |
+
border-radius: 5px;
|
39 |
+
padding: 0.5rem 1rem;
|
40 |
+
font-weight: bold;
|
41 |
+
border: none;
|
42 |
+
transition: all 0.3s;
|
43 |
+
}
|
44 |
+
.stButton>button:hover {
|
45 |
+
background-color: #E68A00;
|
46 |
+
transform: translateY(-2px);
|
47 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
48 |
+
}
|
49 |
+
.query-box {
|
50 |
+
border: 2px solid #FF9900;
|
51 |
+
border-radius: 10px;
|
52 |
+
padding: 10px;
|
53 |
+
}
|
54 |
+
.chat-container {
|
55 |
+
border-radius: 10px;
|
56 |
+
padding: 15px;
|
57 |
+
margin-top: 20px;
|
58 |
+
background-color: #f8f9fa;
|
59 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
60 |
+
}
|
61 |
+
.sidebar-content {
|
62 |
+
padding: 15px;
|
63 |
+
}
|
64 |
+
.profile-container {
|
65 |
+
background-color: #ffffff;
|
66 |
+
border-radius: 10px;
|
67 |
+
padding: 20px;
|
68 |
+
margin-top: 20px;
|
69 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
70 |
+
}
|
71 |
+
.profile-image {
|
72 |
+
border-radius: 50%;
|
73 |
+
width: 150px;
|
74 |
+
height: 150px;
|
75 |
+
object-fit: cover;
|
76 |
+
margin: 0 auto;
|
77 |
+
display: block;
|
78 |
+
border: 3px solid #FF9900;
|
79 |
+
}
|
80 |
+
.divider {
|
81 |
+
margin-top: 1rem;
|
82 |
+
margin-bottom: 1rem;
|
83 |
+
border-top: 1px solid #e9ecef;
|
84 |
+
}
|
85 |
+
.skill-tag {
|
86 |
+
background-color: #FF9900;
|
87 |
+
color: white;
|
88 |
+
padding: 0.2rem 0.5rem;
|
89 |
+
border-radius: 5px;
|
90 |
+
margin-right: 5px;
|
91 |
+
margin-bottom: 5px;
|
92 |
+
display: inline-block;
|
93 |
+
font-size: 0.8rem;
|
94 |
+
}
|
95 |
+
</style>
|
96 |
+
""", unsafe_allow_html=True)
|
97 |
+
|
98 |
+
# Title with custom styling
|
99 |
+
st.markdown('<h1 class="main-title">π Solar Industry AI Assistant</h1>', unsafe_allow_html=True)
|
100 |
+
st.markdown('<p style="text-align: center; font-size: 1.2rem;">π <b>Ask any question related to solar energy, installation, cost, regulations, and more!</b></p>', unsafe_allow_html=True)
|
101 |
+
|
102 |
+
# Session state for chat history
|
103 |
+
if "chat_history" not in st.session_state:
|
104 |
+
st.session_state.chat_history = []
|
105 |
+
|
106 |
+
# Create tabs for main content and about section
|
107 |
+
tab1, tab2 = st.tabs(["π¬ Chat Assistant", "π€ About Me"])
|
108 |
+
|
109 |
+
with tab1:
|
110 |
+
# Layout with columns in the main chat tab
|
111 |
+
col1, col2 = st.columns([3, 1])
|
112 |
+
|
113 |
+
with col1:
|
114 |
+
# Query input with enhanced styling
|
115 |
+
st.markdown('<div class="query-box">', unsafe_allow_html=True)
|
116 |
+
user_query = st.text_area("π‘ Enter your question:", height=100)
|
117 |
+
submit_button = st.button("β‘ Get Answer", use_container_width=True)
|
118 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
119 |
+
|
120 |
+
if submit_button:
|
121 |
+
if user_query.strip():
|
122 |
+
if is_solar_related(user_query): # Check if the query is solar-related
|
123 |
+
with st.spinner("Thinking...π"):
|
124 |
+
time.sleep(1) # Simulate thinking animation
|
125 |
+
response = get_ai_response(user_query)
|
126 |
+
st.session_state.chat_history.append({"question": user_query, "answer": response})
|
127 |
+
|
128 |
+
# Display the current response in a nice box
|
129 |
+
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
130 |
+
st.subheader("π€ AI Response:")
|
131 |
+
st.success(response)
|
132 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
133 |
+
else:
|
134 |
+
st.warning("β οΈ Please ask only solar energy-related questions.")
|
135 |
+
else:
|
136 |
+
st.warning("β οΈ Please enter a question.")
|
137 |
+
|
138 |
+
# Chat history in sidebar in the main chat tab
|
139 |
+
with col2:
|
140 |
+
st.markdown('<div class="sidebar-content">', unsafe_allow_html=True)
|
141 |
+
st.subheader("π Chat History")
|
142 |
+
|
143 |
+
# Export Chat History button
|
144 |
+
if st.button("πΎ Export Chat History", key="export_btn"):
|
145 |
+
chat_data = json.dumps(st.session_state.chat_history, indent=4)
|
146 |
+
st.download_button("οΏ½οΏ½ Download", chat_data, "chat_history.json", "application/json")
|
147 |
+
|
148 |
+
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
149 |
+
|
150 |
+
# Display chat history items
|
151 |
+
for idx, chat in enumerate(st.session_state.chat_history[::-1]):
|
152 |
+
if st.button(f"π¨οΈ {chat['question'][:40]}...", key=f"chat_{idx}"):
|
153 |
+
st.markdown(f"**Q:** {chat['question']}")
|
154 |
+
st.markdown(f"**A:** {chat['answer']}")
|
155 |
+
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
156 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
157 |
+
|
158 |
+
# About Me Tab
|
159 |
+
with tab2:
|
160 |
+
st.markdown('<div class="profile-container">', unsafe_allow_html=True)
|
161 |
+
|
162 |
+
# Profile section with columns for photo and details
|
163 |
+
col1, col2 = st.columns([1, 2])
|
164 |
+
|
165 |
+
with col1:
|
166 |
+
# Profile image placeholder (replace URL with actual image if available)
|
167 |
+
st.markdown('<img src="https://github.com/UditanshuPandey/uditanshupandey.github.io/blob/main/imgs/Photo.png" class="profile-image">', unsafe_allow_html=True)
|
168 |
+
|
169 |
+
with col2:
|
170 |
+
st.markdown("<h2 style='color: #FF9900;'>Uditanshu Pandey</h2>", unsafe_allow_html=True)
|
171 |
+
st.markdown("<p><b>Course:</b> B.Tech (Artificial Intelligence & Machine Learning)</p>", unsafe_allow_html=True)
|
172 |
+
st.markdown("<p><b>College:</b> Delhi Technical Campus, Greater Noida</p>", unsafe_allow_html=True)
|
173 |
+
st.markdown("<p><b>Affiliation:</b> Guru Gobind Singh Indraprastha University, New Delhi</p>", unsafe_allow_html=True)
|
174 |
+
|
175 |
+
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
176 |
+
|
177 |
+
# Introduction
|
178 |
+
st.subheader("π Introduction")
|
179 |
+
st.write("""
|
180 |
+
Enthusiastic and dedicated student with expertise in Python, data structures, algorithms, and machine learning.
|
181 |
+
Proficient with scikit-learn, tensorflow, numpy, and pandas. Experienced with natural language processing.
|
182 |
+
Currently preparing for the GATE exam to enhance my technical knowledge.
|
183 |
+
I am eager to contribute to unique projects and thrive in a dynamic environment.
|
184 |
+
""")
|
185 |
+
|
186 |
+
# Skills section
|
187 |
+
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
188 |
+
st.subheader("π οΈ Skills")
|
189 |
+
|
190 |
+
# Programming Languages
|
191 |
+
st.write("**Programming Languages:**")
|
192 |
+
st.markdown('<div style="display: flex; flex-wrap: wrap; gap: 5px;">' +
|
193 |
+
'<span class="skill-tag">Python</span>' +
|
194 |
+
'<span class="skill-tag">C++</span>' +
|
195 |
+
'<span class="skill-tag">Java</span>' +
|
196 |
+
'</div>', unsafe_allow_html=True)
|
197 |
+
|
198 |
+
# Frameworks & Libraries
|
199 |
+
st.write("**Frameworks & Libraries:**")
|
200 |
+
st.markdown('<div style="display: flex; flex-wrap: wrap; gap: 5px;">' +
|
201 |
+
'<span class="skill-tag">TensorFlow</span>' +
|
202 |
+
'<span class="skill-tag">Scikit-learn</span>' +
|
203 |
+
'<span class="skill-tag">NumPy</span>' +
|
204 |
+
'<span class="skill-tag">Pandas</span>' +
|
205 |
+
'<span class="skill-tag">Streamlit</span>' +
|
206 |
+
'</div>', unsafe_allow_html=True)
|
207 |
+
|
208 |
+
# Areas of Interest
|
209 |
+
st.write("**Areas of Interest:**")
|
210 |
+
st.markdown('<div style="display: flex; flex-wrap: wrap; gap: 5px;">' +
|
211 |
+
'<span class="skill-tag">Machine Learning</span>' +
|
212 |
+
'<span class="skill-tag">Natural Language Processing</span>' +
|
213 |
+
'<span class="skill-tag">Data Structures</span>' +
|
214 |
+
'<span class="skill-tag">Algorithms</span>' +
|
215 |
+
'<span class="skill-tag">Solar Energy</span>' +
|
216 |
+
'</div>', unsafe_allow_html=True)
|
217 |
+
|
218 |
+
# Contact information
|
219 |
+
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
220 |
+
st.subheader("π¬ Contact")
|
221 |
+
col1, col2, col3 = st.columns(3)
|
222 |
+
with col1:
|
223 |
+
st.markdown('<a href="mailto:[email protected]" style="text-decoration: none;"><button style="background-color: #FF9900; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%;">π§ Email</button></a>', unsafe_allow_html=True)
|
224 |
+
with col2:
|
225 |
+
st.markdown('<a href="linkedin.com/in/uditanshupandey" style="text-decoration: none;"><button style="background-color: #0077B5; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%;">π LinkedIn</button></a>', unsafe_allow_html=True)
|
226 |
+
with col3:
|
227 |
+
st.markdown('<a href="https://github.com/UditanshuPandey" style="text-decoration: none;"><button style="background-color: #333; color: white; border: none; padding: 10px; border-radius: 5px; width: 100%;">π» GitHub</button></a>', unsafe_allow_html=True)
|
228 |
+
|
229 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
230 |
+
|
231 |
+
# Footer
|
232 |
+
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
233 |
+
st.markdown('<p style="text-align: center; color: #666;">Β© 2025 Solar Industry AI Assistant | Developed by Uditanshu Pandey</p>', unsafe_allow_html=True)
|
config.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
API_KEY = "AIzaSyDuoxoNgkgWr34vEUBFH7y_gwS-uvsXRYI"
|
filter.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# filter.py - Solar Energy Query Filtering Module
|
2 |
+
|
3 |
+
def is_solar_related(query):
|
4 |
+
"""Check if the query is related to solar energy."""
|
5 |
+
solar_keywords = [
|
6 |
+
"solar", "photovoltaic", "renewable", "solar panel", "solar energy",
|
7 |
+
"solar power", "PV system", "net metering", "solar installation",
|
8 |
+
"inverter", "solar efficiency", "solar cells", "solar farm",
|
9 |
+
"solar battery", "solar thermal", "off-grid solar"
|
10 |
+
]
|
11 |
+
return any(keyword in query.lower() for keyword in solar_keywords)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit>=1.30.0
|
2 |
+
google-generativeai>=0.3.0
|
3 |
+
python-dotenv>=1.0.0
|
4 |
+
json5>=0.9.14
|