|
import streamlit as st
|
|
import google.generativeai as genai
|
|
import os
|
|
import config
|
|
import json
|
|
import time
|
|
from filter import is_solar_related
|
|
|
|
|
|
genai.configure(api_key=config.API_KEY)
|
|
|
|
def get_ai_response(user_input):
|
|
model = genai.GenerativeModel("gemini-pro")
|
|
response = model.generate_content(user_input)
|
|
return response.text if hasattr(response, "text") else "Error fetching response"
|
|
|
|
|
|
st.set_page_config(
|
|
page_title="Solar Industry AI Assistant",
|
|
page_icon="βοΈ",
|
|
layout="wide",
|
|
initial_sidebar_state="expanded"
|
|
)
|
|
|
|
|
|
st.markdown("""
|
|
<style>
|
|
.main-title {
|
|
font-size: 2.5rem !important;
|
|
color: #FF9900 !important;
|
|
text-align: center;
|
|
margin-bottom: 1rem;
|
|
text-shadow: 1px 1px 2px #00000030;
|
|
}
|
|
.stButton>button {
|
|
background-color: #FF9900;
|
|
color: white;
|
|
border-radius: 5px;
|
|
padding: 0.5rem 1rem;
|
|
font-weight: bold;
|
|
border: none;
|
|
transition: all 0.3s;
|
|
}
|
|
.stButton>button:hover {
|
|
background-color: #E68A00;
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
|
}
|
|
.query-box {
|
|
border: 2px solid #FF9900;
|
|
border-radius: 10px;
|
|
padding: 10px;
|
|
}
|
|
.chat-container {
|
|
border-radius: 10px;
|
|
padding: 15px;
|
|
margin-top: 20px;
|
|
background-color: #f8f9fa;
|
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
|
}
|
|
.sidebar-content {
|
|
padding: 15px;
|
|
}
|
|
.profile-container {
|
|
background-color: #ffffff;
|
|
border-radius: 10px;
|
|
padding: 20px;
|
|
margin-top: 20px;
|
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
|
}
|
|
.profile-image {
|
|
border-radius: 50%;
|
|
width: 150px;
|
|
height: 150px;
|
|
object-fit: cover;
|
|
margin: 0 auto;
|
|
display: block;
|
|
border: 3px solid #FF9900;
|
|
}
|
|
.divider {
|
|
margin-top: 1rem;
|
|
margin-bottom: 1rem;
|
|
border-top: 1px solid #e9ecef;
|
|
}
|
|
.skill-tag {
|
|
background-color: #FF9900;
|
|
color: white;
|
|
padding: 0.2rem 0.5rem;
|
|
border-radius: 5px;
|
|
margin-right: 5px;
|
|
margin-bottom: 5px;
|
|
display: inline-block;
|
|
font-size: 0.8rem;
|
|
}
|
|
</style>
|
|
""", unsafe_allow_html=True)
|
|
|
|
|
|
st.markdown('<h1 class="main-title">π Solar Industry AI Assistant</h1>', unsafe_allow_html=True)
|
|
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)
|
|
|
|
|
|
if "chat_history" not in st.session_state:
|
|
st.session_state.chat_history = []
|
|
|
|
|
|
tab1, tab2 = st.tabs(["π¬ Chat Assistant", "π€ About Me"])
|
|
|
|
with tab1:
|
|
|
|
col1, col2 = st.columns([3, 1])
|
|
|
|
with col1:
|
|
|
|
st.markdown('<div class="query-box">', unsafe_allow_html=True)
|
|
user_query = st.text_area("π‘ Enter your question:", height=100)
|
|
submit_button = st.button("β‘ Get Answer", use_container_width=True)
|
|
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
if submit_button:
|
|
if user_query.strip():
|
|
if is_solar_related(user_query):
|
|
with st.spinner("Thinking...π"):
|
|
time.sleep(1)
|
|
response = get_ai_response(user_query)
|
|
st.session_state.chat_history.append({"question": user_query, "answer": response})
|
|
|
|
|
|
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
|
st.subheader("π€ AI Response:")
|
|
st.success(response)
|
|
st.markdown('</div>', unsafe_allow_html=True)
|
|
else:
|
|
st.warning("β οΈ Please ask only solar energy-related questions.")
|
|
else:
|
|
st.warning("β οΈ Please enter a question.")
|
|
|
|
|
|
with col2:
|
|
st.markdown('<div class="sidebar-content">', unsafe_allow_html=True)
|
|
st.subheader("π Chat History")
|
|
|
|
|
|
if st.button("πΎ Export Chat History", key="export_btn"):
|
|
chat_data = json.dumps(st.session_state.chat_history, indent=4)
|
|
st.download_button("π₯ Download", chat_data, "chat_history.json", "application/json")
|
|
|
|
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
|
|
|
|
|
for idx, chat in enumerate(st.session_state.chat_history[::-1]):
|
|
if st.button(f"π¨οΈ {chat['question'][:40]}...", key=f"chat_{idx}"):
|
|
st.markdown(f"**Q:** {chat['question']}")
|
|
st.markdown(f"**A:** {chat['answer']}")
|
|
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
|
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
with tab2:
|
|
st.markdown('<div class="profile-container">', unsafe_allow_html=True)
|
|
|
|
|
|
col1, col2 = st.columns([1, 2])
|
|
|
|
with col1:
|
|
|
|
st.markdown('<img src="https://github.com/UditanshuPandey/uditanshupandey.github.io/blob/main/imgs/Photo.png" class="profile-image">', unsafe_allow_html=True)
|
|
|
|
with col2:
|
|
st.markdown("<h2 style='color: #FF9900;'>Uditanshu Pandey</h2>", unsafe_allow_html=True)
|
|
st.markdown("<p><b>Course:</b> B.Tech (Artificial Intelligence & Machine Learning)</p>", unsafe_allow_html=True)
|
|
st.markdown("<p><b>College:</b> Delhi Technical Campus, Greater Noida</p>", unsafe_allow_html=True)
|
|
st.markdown("<p><b>Affiliation:</b> Guru Gobind Singh Indraprastha University, New Delhi</p>", unsafe_allow_html=True)
|
|
|
|
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
|
|
|
|
|
st.subheader("π Introduction")
|
|
st.write("""
|
|
Enthusiastic and dedicated student with expertise in Python, data structures, algorithms, and machine learning.
|
|
Proficient with scikit-learn, tensorflow, numpy, and pandas. Experienced with natural language processing.
|
|
Currently preparing for the GATE exam to enhance my technical knowledge.
|
|
I am eager to contribute to unique projects and thrive in a dynamic environment.
|
|
""")
|
|
|
|
|
|
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
|
st.subheader("π οΈ Skills")
|
|
|
|
|
|
st.write("**Programming Languages:**")
|
|
st.markdown('<div style="display: flex; flex-wrap: wrap; gap: 5px;">' +
|
|
'<span class="skill-tag">Python</span>' +
|
|
'<span class="skill-tag">C++</span>' +
|
|
'<span class="skill-tag">Java</span>' +
|
|
'</div>', unsafe_allow_html=True)
|
|
|
|
|
|
st.write("**Frameworks & Libraries:**")
|
|
st.markdown('<div style="display: flex; flex-wrap: wrap; gap: 5px;">' +
|
|
'<span class="skill-tag">TensorFlow</span>' +
|
|
'<span class="skill-tag">Scikit-learn</span>' +
|
|
'<span class="skill-tag">NumPy</span>' +
|
|
'<span class="skill-tag">Pandas</span>' +
|
|
'<span class="skill-tag">Streamlit</span>' +
|
|
'</div>', unsafe_allow_html=True)
|
|
|
|
|
|
st.write("**Areas of Interest:**")
|
|
st.markdown('<div style="display: flex; flex-wrap: wrap; gap: 5px;">' +
|
|
'<span class="skill-tag">Machine Learning</span>' +
|
|
'<span class="skill-tag">Natural Language Processing</span>' +
|
|
'<span class="skill-tag">Data Structures</span>' +
|
|
'<span class="skill-tag">Algorithms</span>' +
|
|
'<span class="skill-tag">Solar Energy</span>' +
|
|
'</div>', unsafe_allow_html=True)
|
|
|
|
|
|
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
|
st.subheader("π¬ Contact")
|
|
col1, col2, col3 = st.columns(3)
|
|
with col1:
|
|
st.markdown('<a href="mailto:uditanshup114@gmail.com" 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)
|
|
with col2:
|
|
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)
|
|
with col3:
|
|
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)
|
|
|
|
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
st.markdown('<div class="divider"></div>', unsafe_allow_html=True)
|
|
st.markdown('<p style="text-align: center; color: #666;">Β© 2025 Solar Industry AI Assistant | Developed by Uditanshu Pandey</p>', unsafe_allow_html=True)
|
|
|