Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.express as px
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
+
|
7 |
+
def main():
|
8 |
+
st.set_page_config(layout="wide")
|
9 |
+
|
10 |
+
# Dashboard selection
|
11 |
+
analysis_type = st.sidebar.selectbox(
|
12 |
+
"Choose Analysis Type",
|
13 |
+
["CSV Data Analysis", "PDF Text Analysis", "Excel Data Analysis"]
|
14 |
+
)
|
15 |
+
|
16 |
+
if analysis_type == "CSV Data Analysis":
|
17 |
+
csv_analysis()
|
18 |
+
elif analysis_type == "PDF Text Analysis":
|
19 |
+
pdf_analysis()
|
20 |
+
elif analysis_type == "Excel Data Analysis":
|
21 |
+
excel_analysis()
|
22 |
+
|
23 |
+
# Add your functions below...
|
24 |
+
|
25 |
+
def csv_analysis():
|
26 |
+
st.header("CSV Data Analysis")
|
27 |
+
uploaded_file = st.file_uploader("Upload CSV", type="csv")
|
28 |
+
|
29 |
+
if uploaded_file:
|
30 |
+
df = pd.read_csv(uploaded_file)
|
31 |
+
|
32 |
+
# Basic stats
|
33 |
+
st.subheader("Basic Statistics")
|
34 |
+
st.write(df.describe())
|
35 |
+
|
36 |
+
# Interactive visualization
|
37 |
+
st.subheader("Data Visualization")
|
38 |
+
columns = df.columns.tolist()
|
39 |
+
x_axis = st.selectbox("X Axis", columns)
|
40 |
+
y_axis = st.selectbox("Y Axis", columns)
|
41 |
+
|
42 |
+
chart = px.scatter(df, x=x_axis, y=y_axis, title=f"{y_axis} vs {x_axis}")
|
43 |
+
st.plotly_chart(chart, use_container_width=True)
|
44 |
+
|
45 |
+
|
46 |
+
def pdf_analysis():
|
47 |
+
st.header("PDF Text Analysis")
|
48 |
+
uploaded_file = st.file_uploader("Upload PDF", type="pdf")
|
49 |
+
|
50 |
+
if uploaded_file:
|
51 |
+
# PDF text extraction
|
52 |
+
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
53 |
+
text = "\n".join([page.extract_text() for page in pdf_reader.pages])
|
54 |
+
|
55 |
+
# Text metrics
|
56 |
+
st.subheader("Document Metrics")
|
57 |
+
col1, col2, col3 = st.columns(3)
|
58 |
+
col1.metric("Pages", len(pdf_reader.pages))
|
59 |
+
col2.metric("Words", len(text.split()))
|
60 |
+
col3.metric("Characters", len(text))
|
61 |
+
|
62 |
+
# Word cloud
|
63 |
+
st.subheader("Word Cloud")
|
64 |
+
wordcloud = WordCloud().generate(text)
|
65 |
+
plt.imshow(wordcloud, interpolation='bilinear')
|
66 |
+
plt.axis("off")
|
67 |
+
st.pyplot(plt)
|
68 |
+
|
69 |
+
def excel_analysis():
|
70 |
+
st.header("Excel Data Analysis")
|
71 |
+
uploaded_file = st.file_uploader("Upload Excel", type=["xlsx", "xls"])
|
72 |
+
|
73 |
+
if uploaded_file:
|
74 |
+
# Read all sheets
|
75 |
+
xls = pd.ExcelFile(uploaded_file)
|
76 |
+
sheet_names = xls.sheet_names
|
77 |
+
selected_sheet = st.selectbox("Select Sheet", sheet_names)
|
78 |
+
|
79 |
+
df = pd.read_excel(xls, sheet_name=selected_sheet)
|
80 |
+
|
81 |
+
# Show data and visualization
|
82 |
+
st.subheader("Data Preview")
|
83 |
+
st.dataframe(df.head())
|
84 |
+
|
85 |
+
st.subheader("Column Distribution")
|
86 |
+
selected_column = st.selectbox("Select Column", df.columns)
|
87 |
+
fig = px.histogram(df, x=selected_column)
|
88 |
+
st.plotly_chart(fig, use_container_width=True)
|