Team Ai
Apppublic

Akshayram1/data_visualization

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py54 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3import plotly.express as px4import openai5 6# Setup OpenAI API7openai.api_key = st.text_input("Enter your OpenAI API key", type="password")8 9# App Title10st.title("Bi-Weekly Report Visualizer")11 12# Upload Excel File13uploaded_file = st.file_uploader("Upload your Excel file", type=["xls", "xlsx"])14 15if uploaded_file is not None:16    # Load data17    df = pd.read_excel(uploaded_file)18 19    # Display raw data20    st.write("### Raw Data")21    st.dataframe(df)22 23    # Extract relevant columns (assume "Week", "Category", and "Hours" columns exist in the sheet)24    if {"Week", "Category", "Hours"}.issubset(df.columns):25        # Summarize data for visualization26        summary = df.groupby(["Week", "Category"]).sum().reset_index()27 28        # Visualize data as a pie chart for each week29        st.write("### Weekly Time Allocation")30        weeks = summary["Week"].unique()31        for week in weeks:32            week_data = summary[summary["Week"] == week]33            fig = px.pie(week_data, values="Hours", names="Category", title=f"Week: {week}")34            st.plotly_chart(fig)35 36        # Generate descriptive insights using OpenAI37        if st.button("Generate Insights"):38            # Get summary in text form39            insights_data = summary.to_string(index=False)40            # OpenAI prompt41            prompt = f"Provide insights about time allocation trends in the following data:\n\n{insights_data}"42            try:43                response = openai.Completion.create(44                    engine="text-davinci-003",45                    prompt=prompt,46                    max_tokens=15047                )48                st.write("### Insights")49                st.text(response.choices[0].text.strip())50            except Exception as e:51                st.error(f"Failed to generate insights: {e}")52    else:53        st.error("The Excel file doesn't have the required columns: 'Week', 'Category', and 'Hours'.")54