Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import plotly.express as px | |
import openai | |
# Setup OpenAI API | |
openai.api_key = st.text_input("Enter your OpenAI API key", type="password") | |
# App Title | |
st.title("Bi-Weekly Report Visualizer") | |
# Upload Excel File | |
uploaded_file = st.file_uploader("Upload your Excel file", type=["xls", "xlsx"]) | |
if uploaded_file is not None: | |
# Load data | |
df = pd.read_excel(uploaded_file) | |
# Display raw data | |
st.write("### Raw Data") | |
st.dataframe(df) | |
# Extract relevant columns (assume "Week", "Category", and "Hours" columns exist in the sheet) | |
if {"Week", "Category", "Hours"}.issubset(df.columns): | |
# Summarize data for visualization | |
summary = df.groupby(["Week", "Category"]).sum().reset_index() | |
# Visualize data as a pie chart for each week | |
st.write("### Weekly Time Allocation") | |
weeks = summary["Week"].unique() | |
for week in weeks: | |
week_data = summary[summary["Week"] == week] | |
fig = px.pie(week_data, values="Hours", names="Category", title=f"Week: {week}") | |
st.plotly_chart(fig) | |
# Generate descriptive insights using OpenAI | |
if st.button("Generate Insights"): | |
# Get summary in text form | |
insights_data = summary.to_string(index=False) | |
# OpenAI prompt | |
prompt = f"Provide insights about time allocation trends in the following data:\n\n{insights_data}" | |
try: | |
response = openai.Completion.create( | |
engine="text-davinci-003", | |
prompt=prompt, | |
max_tokens=150 | |
) | |
st.write("### Insights") | |
st.text(response.choices[0].text.strip()) | |
except Exception as e: | |
st.error(f"Failed to generate insights: {e}") | |
else: | |
st.error("The Excel file doesn't have the required columns: 'Week', 'Category', and 'Hours'.") | |