import streamlit as st import pandas as pd import plotly.express as px import plotly.graph_objects as go # Title of the App st.title("Excel Graph Visualizer") # File Upload Section uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx", "xls"]) if uploaded_file: # Read Excel file try: df = pd.read_excel(uploaded_file) st.write("Data Preview:") st.dataframe(df) # Dropdown for selecting graph type graph_type = st.selectbox( "Select Graph Type", ["Clustered Column", "Line Chart", "Single Axis", "Double Axis"] ) # Dropdowns for selecting columns for x and y axes x_axis = st.selectbox("Select X-axis column", df.columns) y_axis = st.multiselect("Select Y-axis column(s)", df.columns) # Generate Graph based on selection if graph_type == "Clustered Column" and len(y_axis) > 0: fig = px.bar(df, x=x_axis, y=y_axis, barmode="group") st.plotly_chart(fig) elif graph_type == "Line Chart" and len(y_axis) > 0: fig = px.line(df, x=x_axis, y=y_axis) st.plotly_chart(fig) elif graph_type == "Single Axis" and len(y_axis) == 1: fig = px.line(df, x=x_axis, y=y_axis[0]) st.plotly_chart(fig) elif graph_type == "Double Axis" and len(y_axis) == 2: fig = go.Figure() fig.add_trace(go.Scatter(x=df[x_axis], y=df[y_axis[0]], mode='lines', name=y_axis[0])) fig.add_trace(go.Scatter(x=df[x_axis], y=df[y_axis[1]], mode='lines', name=y_axis[1], yaxis="y2")) # Add a secondary y-axis fig.update_layout( yaxis2=dict( title=y_axis[1], overlaying='y', side='right' ), title="Double Axis Graph" ) st.plotly_chart(fig) else: st.warning("Please select appropriate columns and graph type.") except Exception as e: st.error(f"Error loading file: {e}") else: st.info("Please upload an Excel file to get started.") # Add Footer st.write("---") st.write("Developed using [Streamlit](https://streamlit.io) and [Hugging Face Spaces](https://huggingface.co/spaces).")