Spaces:
Sleeping
Sleeping
File size: 1,971 Bytes
f1ff50c 2c59485 f1ff50c 18eaccd 2c59485 f1ff50c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
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'.")
|