akazmi commited on
Commit
96b1be4
·
verified ·
1 Parent(s): 777a35b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import plotly.graph_objects as go
5
+
6
+ # Title of the App
7
+ st.title("Excel Graph Visualizer")
8
+
9
+ # File Upload Section
10
+ uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx", "xls"])
11
+
12
+ if uploaded_file:
13
+ # Read Excel file
14
+ try:
15
+ df = pd.read_excel(uploaded_file)
16
+ st.write("Data Preview:")
17
+ st.dataframe(df)
18
+
19
+ # Dropdown for selecting graph type
20
+ graph_type = st.selectbox(
21
+ "Select Graph Type",
22
+ ["Clustered Column", "Line Chart", "Single Axis", "Double Axis"]
23
+ )
24
+
25
+ # Dropdowns for selecting columns for x and y axes
26
+ x_axis = st.selectbox("Select X-axis column", df.columns)
27
+ y_axis = st.multiselect("Select Y-axis column(s)", df.columns)
28
+
29
+ # Generate Graph based on selection
30
+ if graph_type == "Clustered Column" and len(y_axis) > 0:
31
+ fig = px.bar(df, x=x_axis, y=y_axis, barmode="group")
32
+ st.plotly_chart(fig)
33
+
34
+ elif graph_type == "Line Chart" and len(y_axis) > 0:
35
+ fig = px.line(df, x=x_axis, y=y_axis)
36
+ st.plotly_chart(fig)
37
+
38
+ elif graph_type == "Single Axis" and len(y_axis) == 1:
39
+ fig = px.line(df, x=x_axis, y=y_axis[0])
40
+ st.plotly_chart(fig)
41
+
42
+ elif graph_type == "Double Axis" and len(y_axis) == 2:
43
+ fig = go.Figure()
44
+ fig.add_trace(go.Scatter(x=df[x_axis], y=df[y_axis[0]], mode='lines', name=y_axis[0]))
45
+ fig.add_trace(go.Scatter(x=df[x_axis], y=df[y_axis[1]], mode='lines', name=y_axis[1], yaxis="y2"))
46
+
47
+ # Add a secondary y-axis
48
+ fig.update_layout(
49
+ yaxis2=dict(
50
+ title=y_axis[1],
51
+ overlaying='y',
52
+ side='right'
53
+ ),
54
+ title="Double Axis Graph"
55
+ )
56
+ st.plotly_chart(fig)
57
+ else:
58
+ st.warning("Please select appropriate columns and graph type.")
59
+ except Exception as e:
60
+ st.error(f"Error loading file: {e}")
61
+ else:
62
+ st.info("Please upload an Excel file to get started.")
63
+
64
+ # Add Footer
65
+ st.write("---")
66
+ st.write("Developed using [Streamlit](https://streamlit.io) and [Hugging Face Spaces](https://huggingface.co/spaces).")