Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,29 +80,6 @@ elif input_option == "Upload CSV File":
|
|
| 80 |
except Exception as e:
|
| 81 |
st.error(f"Error loading file: {e}")
|
| 82 |
|
| 83 |
-
def save_as_txt(content, filename):
|
| 84 |
-
with open(filename, "w") as f:
|
| 85 |
-
f.write(content)
|
| 86 |
-
return filename
|
| 87 |
-
|
| 88 |
-
def save_as_pdf(content, filename):
|
| 89 |
-
from fpdf import FPDF
|
| 90 |
-
pdf = FPDF()
|
| 91 |
-
pdf.add_page()
|
| 92 |
-
pdf.set_font("Arial", size=12)
|
| 93 |
-
for line in content.split('\n'):
|
| 94 |
-
pdf.multi_cell(0, 10, line)
|
| 95 |
-
pdf.output(filename)
|
| 96 |
-
return filename
|
| 97 |
-
|
| 98 |
-
# Show Dataset Preview Only After Loading
|
| 99 |
-
if st.session_state.df is not None and st.session_state.show_preview:
|
| 100 |
-
st.subheader("π Dataset Preview")
|
| 101 |
-
st.dataframe(st.session_state.df.head())
|
| 102 |
-
|
| 103 |
-
import tempfile
|
| 104 |
-
from fpdf import FPDF
|
| 105 |
-
|
| 106 |
# Helper Functions for Download
|
| 107 |
def save_as_txt(content, filename):
|
| 108 |
with open(filename, "w") as f:
|
|
@@ -171,7 +148,7 @@ if st.session_state.df is not None:
|
|
| 171 |
|
| 172 |
conclusion_writer = Agent(
|
| 173 |
role="Conclusion Specialist",
|
| 174 |
-
goal="Summarize findings into a clear and concise 3-5 line Conclusion highlighting only the most important
|
| 175 |
backstory="An expert in crafting impactful and clear conclusions.",
|
| 176 |
llm=llm,
|
| 177 |
)
|
|
@@ -227,26 +204,27 @@ if st.session_state.df is not None:
|
|
| 227 |
query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
|
| 228 |
if st.button("Submit Query"):
|
| 229 |
with st.spinner("Processing query..."):
|
| 230 |
-
|
| 231 |
-
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
|
|
|
| 235 |
|
| 236 |
-
st.markdown(
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
|
|
|
|
| 244 |
fig_salary = px.box(st.session_state.df, x="job_title", y="salary_in_usd", title="Salary Distribution by Job Title")
|
| 245 |
st.plotly_chart(fig_salary)
|
| 246 |
st.caption("π Salary distribution across different job titles.")
|
| 247 |
|
| 248 |
-
fig_experience = px.bar(st.session_state.df.groupby("experience_level")["salary_in_usd"].mean().reset_index(),
|
| 249 |
-
x="experience_level", y="salary_in_usd", title="Average Salary by Experience Level")
|
| 250 |
st.plotly_chart(fig_experience)
|
| 251 |
st.caption("π Average salary based on experience level.")
|
| 252 |
|
|
@@ -254,7 +232,7 @@ if st.session_state.df is not None:
|
|
| 254 |
st.plotly_chart(fig_employment)
|
| 255 |
st.caption("π Salary distribution across employment types.")
|
| 256 |
|
| 257 |
-
st.markdown(
|
| 258 |
|
| 259 |
# Full Data Visualization Tab
|
| 260 |
with tab2:
|
|
@@ -271,15 +249,12 @@ if st.session_state.df is not None:
|
|
| 271 |
|
| 272 |
fig3 = px.box(st.session_state.df, x="employment_type", y="salary_in_usd", title="Salary Distribution by Employment Type")
|
| 273 |
st.plotly_chart(fig3)
|
| 274 |
-
st.caption("π Salary distribution
|
| 275 |
-
|
| 276 |
-
tab2_content = "Comprehensive Data Visualizations:\n"
|
| 277 |
-
tab2_content += "- Job Title Frequency\n"
|
| 278 |
-
tab2_content += "- Average Salary by Experience Level\n"
|
| 279 |
-
tab2_content += "- Salary Distribution by Employment Type\n"
|
| 280 |
|
|
|
|
| 281 |
tab2_txt = save_as_txt(tab2_content, "Tab2_Visualizations.txt")
|
| 282 |
tab2_pdf = save_as_pdf(tab2_content, "Tab2_Visualizations.pdf")
|
|
|
|
| 283 |
st.download_button("Download Tab 2 Summary as TXT", open(tab2_txt, "rb"), file_name="Tab2_Visualizations.txt")
|
| 284 |
st.download_button("Download Tab 2 Summary as PDF", open(tab2_pdf, "rb"), file_name="Tab2_Visualizations.pdf")
|
| 285 |
|
|
|
|
| 80 |
except Exception as e:
|
| 81 |
st.error(f"Error loading file: {e}")
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
# Helper Functions for Download
|
| 84 |
def save_as_txt(content, filename):
|
| 85 |
with open(filename, "w") as f:
|
|
|
|
| 148 |
|
| 149 |
conclusion_writer = Agent(
|
| 150 |
role="Conclusion Specialist",
|
| 151 |
+
goal="Summarize findings into a clear and concise 3-5 line Conclusion highlighting only the most important insights.",
|
| 152 |
backstory="An expert in crafting impactful and clear conclusions.",
|
| 153 |
llm=llm,
|
| 154 |
)
|
|
|
|
| 204 |
query = st.text_area("Enter Query:", value="Provide insights into the salary of a Principal Data Scientist.")
|
| 205 |
if st.button("Submit Query"):
|
| 206 |
with st.spinner("Processing query..."):
|
| 207 |
+
report_result = crew_report.kickoff(inputs={"query": query + " Provide detailed analysis but DO NOT include Conclusion."})
|
| 208 |
+
conclusion_result = crew_conclusion.kickoff(inputs={"query": query + " Provide ONLY the most important insights in 3-5 concise lines."})
|
| 209 |
|
| 210 |
+
# Convert results to string
|
| 211 |
+
report_text = str(report_result)
|
| 212 |
+
conclusion_text = str(conclusion_result)
|
| 213 |
|
| 214 |
+
st.markdown(report_text if report_text else "β οΈ No Report Generated.")
|
| 215 |
|
| 216 |
+
# Download Buttons for Tab 1
|
| 217 |
+
tab1_txt = save_as_txt(report_text, "Tab1_Report.txt")
|
| 218 |
+
tab1_pdf = save_as_pdf(report_text, "Tab1_Report.pdf")
|
| 219 |
+
st.download_button("Download Tab 1 Report as TXT", open(tab1_txt, "rb"), file_name="Tab1_Report.txt")
|
| 220 |
+
st.download_button("Download Tab 1 Report as PDF", open(tab1_pdf, "rb"), file_name="Tab1_Report.pdf")
|
| 221 |
|
| 222 |
+
# Visualizations with captions
|
| 223 |
fig_salary = px.box(st.session_state.df, x="job_title", y="salary_in_usd", title="Salary Distribution by Job Title")
|
| 224 |
st.plotly_chart(fig_salary)
|
| 225 |
st.caption("π Salary distribution across different job titles.")
|
| 226 |
|
| 227 |
+
fig_experience = px.bar(st.session_state.df.groupby("experience_level")["salary_in_usd"].mean().reset_index(), x="experience_level", y="salary_in_usd", title="Average Salary by Experience Level")
|
|
|
|
| 228 |
st.plotly_chart(fig_experience)
|
| 229 |
st.caption("π Average salary based on experience level.")
|
| 230 |
|
|
|
|
| 232 |
st.plotly_chart(fig_employment)
|
| 233 |
st.caption("π Salary distribution across employment types.")
|
| 234 |
|
| 235 |
+
st.markdown(conclusion_text if conclusion_text else "β οΈ No Conclusion Generated.")
|
| 236 |
|
| 237 |
# Full Data Visualization Tab
|
| 238 |
with tab2:
|
|
|
|
| 249 |
|
| 250 |
fig3 = px.box(st.session_state.df, x="employment_type", y="salary_in_usd", title="Salary Distribution by Employment Type")
|
| 251 |
st.plotly_chart(fig3)
|
| 252 |
+
st.caption("π Salary distribution across employment types.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
|
| 254 |
+
tab2_content = "Comprehensive Data Visualizations:\n- Job Title Frequency\n- Average Salary by Experience Level\n- Salary Distribution by Employment Type\n"
|
| 255 |
tab2_txt = save_as_txt(tab2_content, "Tab2_Visualizations.txt")
|
| 256 |
tab2_pdf = save_as_pdf(tab2_content, "Tab2_Visualizations.pdf")
|
| 257 |
+
|
| 258 |
st.download_button("Download Tab 2 Summary as TXT", open(tab2_txt, "rb"), file_name="Tab2_Visualizations.txt")
|
| 259 |
st.download_button("Download Tab 2 Summary as PDF", open(tab2_pdf, "rb"), file_name="Tab2_Visualizations.pdf")
|
| 260 |
|