Update app.py
Browse files
app.py
CHANGED
|
@@ -1,233 +1,101 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
-
import os
|
| 4 |
-
import config
|
| 5 |
import json
|
| 6 |
import time
|
| 7 |
-
from filter import is_solar_related
|
| 8 |
|
| 9 |
# Configure Gemini API
|
| 10 |
-
genai.configure(api_key=
|
| 11 |
|
| 12 |
def get_ai_response(user_input):
|
| 13 |
-
model = genai.GenerativeModel("gemini-pro")
|
| 14 |
response = model.generate_content(user_input)
|
| 15 |
return response.text if hasattr(response, "text") else "Error fetching response"
|
| 16 |
|
| 17 |
-
#
|
| 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 |
-
#
|
| 26 |
-
st.
|
| 27 |
-
|
| 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 |
-
#
|
| 99 |
-
st.
|
| 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 |
-
#
|
| 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 |
-
|
| 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):
|
| 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"
|
| 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.
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
# Profile image placeholder (replace URL with actual image if available)
|
| 167 |
-
st.markdown('<img src="https://ibb.co/zTB113PB" 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 |
-
|
| 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.
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
'</div>', unsafe_allow_html=True)
|
| 197 |
|
| 198 |
-
|
| 199 |
-
st.write("
|
| 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 |
-
|
| 209 |
-
st.write("
|
| 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(
|
| 224 |
with col2:
|
| 225 |
-
st.markdown(
|
| 226 |
with col3:
|
| 227 |
-
st.markdown(
|
| 228 |
-
|
| 229 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 230 |
|
| 231 |
-
|
| 232 |
-
st.markdown(
|
| 233 |
-
st.markdown('<p style="text-align: center; color: #666;">Β© 2025 Solar Industry AI Assistant | Developed by Uditanshu Pandey</p>', unsafe_allow_html=True)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
|
|
|
|
|
|
| 3 |
import json
|
| 4 |
import time
|
| 5 |
+
from filter import is_solar_related
|
| 6 |
|
| 7 |
# Configure Gemini API
|
| 8 |
+
genai.configure(api_key="YOUR_API_KEY")
|
| 9 |
|
| 10 |
def get_ai_response(user_input):
|
| 11 |
+
model = genai.GenerativeModel("gemini-pro")
|
| 12 |
response = model.generate_content(user_input)
|
| 13 |
return response.text if hasattr(response, "text") else "Error fetching response"
|
| 14 |
|
| 15 |
+
# Page config
|
| 16 |
st.set_page_config(
|
| 17 |
page_title="Solar Industry AI Assistant",
|
| 18 |
page_icon="βοΈ",
|
| 19 |
+
layout="wide"
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
+
# Title
|
| 23 |
+
st.title("π Solar Industry AI Assistant")
|
| 24 |
+
st.markdown("Ask any question related to solar energy, installation, cost, regulations, and more!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Create tabs
|
| 27 |
+
tab1, tab2 = st.tabs(["π¬ Chat Assistant", "π€ About Me"])
|
|
|
|
| 28 |
|
| 29 |
+
# Initialize chat history
|
| 30 |
if "chat_history" not in st.session_state:
|
| 31 |
st.session_state.chat_history = []
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
with tab1:
|
|
|
|
| 34 |
col1, col2 = st.columns([3, 1])
|
| 35 |
|
| 36 |
with col1:
|
|
|
|
|
|
|
| 37 |
user_query = st.text_area("π‘ Enter your question:", height=100)
|
| 38 |
+
if st.button("β‘ Get Answer"):
|
|
|
|
|
|
|
|
|
|
| 39 |
if user_query.strip():
|
| 40 |
+
if is_solar_related(user_query):
|
| 41 |
with st.spinner("Thinking...π"):
|
|
|
|
| 42 |
response = get_ai_response(user_query)
|
| 43 |
st.session_state.chat_history.append({"question": user_query, "answer": response})
|
|
|
|
|
|
|
|
|
|
| 44 |
st.subheader("π€ AI Response:")
|
| 45 |
st.success(response)
|
|
|
|
| 46 |
else:
|
| 47 |
st.warning("β οΈ Please ask only solar energy-related questions.")
|
| 48 |
else:
|
| 49 |
st.warning("β οΈ Please enter a question.")
|
| 50 |
|
|
|
|
| 51 |
with col2:
|
|
|
|
| 52 |
st.subheader("π Chat History")
|
| 53 |
+
if st.button("πΎ Export Chat History"):
|
|
|
|
|
|
|
| 54 |
chat_data = json.dumps(st.session_state.chat_history, indent=4)
|
| 55 |
+
st.download_button("π₯ Download", chat_data, "chat_history.json")
|
|
|
|
|
|
|
| 56 |
|
|
|
|
| 57 |
for idx, chat in enumerate(st.session_state.chat_history[::-1]):
|
| 58 |
if st.button(f"π¨οΈ {chat['question'][:40]}...", key=f"chat_{idx}"):
|
| 59 |
st.markdown(f"**Q:** {chat['question']}")
|
| 60 |
st.markdown(f"**A:** {chat['answer']}")
|
|
|
|
|
|
|
| 61 |
|
|
|
|
| 62 |
with tab2:
|
| 63 |
+
st.header("Uditanshu Pandey")
|
| 64 |
+
st.markdown("""
|
| 65 |
+
**Course:** B.Tech (Artificial Intelligence & Machine Learning)
|
| 66 |
+
**College:** Delhi Technical Campus, Greater Noida
|
| 67 |
+
**Affiliation:** Guru Gobind Singh Indraprastha University, New Delhi
|
| 68 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
|
|
|
| 70 |
st.subheader("π Introduction")
|
| 71 |
st.write("""
|
| 72 |
Enthusiastic and dedicated student with expertise in Python, data structures, algorithms, and machine learning.
|
|
|
|
| 73 |
Currently preparing for the GATE exam to enhance my technical knowledge.
|
| 74 |
+
Eager to contribute to unique projects and thrive in a dynamic environment.
|
| 75 |
""")
|
| 76 |
|
|
|
|
|
|
|
| 77 |
st.subheader("π οΈ Skills")
|
| 78 |
|
|
|
|
| 79 |
st.write("**Programming Languages:**")
|
| 80 |
+
st.write("Python, C++, SQL, SQLite, MongoDB, Django")
|
| 81 |
+
|
| 82 |
+
st.write("**Deep Learning Frameworks:**")
|
| 83 |
+
st.write("TensorFlow, Keras")
|
|
|
|
| 84 |
|
| 85 |
+
st.write("**Web Framework:**")
|
| 86 |
+
st.write("Django, HTML, CSS, Bootstrap, Javascript")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
st.write("**Libraries & Tools:**")
|
| 89 |
+
st.write("NumPy, Pandas, Scikit-learn, OpenCV, NLTK, Pillow, Streamlit, Matplotlib, Seaborn, Git")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
|
|
|
|
|
|
| 91 |
st.subheader("π¬ Contact")
|
| 92 |
col1, col2, col3 = st.columns(3)
|
| 93 |
with col1:
|
| 94 |
+
st.markdown("[π§ Email](mailto:uditanshupandey@example.com)")
|
| 95 |
with col2:
|
| 96 |
+
st.markdown("[π LinkedIn](https://linkedin.com/in/)")
|
| 97 |
with col3:
|
| 98 |
+
st.markdown("[π» GitHub](https://github.com/)")
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
st.markdown("---")
|
| 101 |
+
st.markdown("Β© 2025 Solar Industry AI Assistant | Developed by Uditanshu Pandey")
|
|
|