Spaces:
Sleeping
Sleeping
Commit
·
1dad147
verified
·
0
Parent(s):
initial commit
Browse files- .gitattributes +35 -0
- README.md +12 -0
- app.py +63 -0
- requirements.txt +5 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Smart Xlsx
|
| 3 |
+
emoji: 📚
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.36.2
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
import io
|
| 6 |
+
|
| 7 |
+
def get_columns(file):
|
| 8 |
+
df = pd.read_excel(file.name)
|
| 9 |
+
cols = df.columns.tolist()
|
| 10 |
+
return cols, df
|
| 11 |
+
|
| 12 |
+
def plot_chosen_columns(df, x_col, y_col=None):
|
| 13 |
+
plots = []
|
| 14 |
+
fig, ax = plt.subplots(figsize=(6,4))
|
| 15 |
+
if y_col:
|
| 16 |
+
# If both x and y chosen, scatterplot or lineplot
|
| 17 |
+
if pd.api.types.is_numeric_dtype(df[x_col]) and pd.api.types.is_numeric_dtype(df[y_col]):
|
| 18 |
+
sns.scatterplot(data=df, x=x_col, y=y_col, ax=ax)
|
| 19 |
+
ax.set_title(f"Scatter plot of {x_col} vs {y_col}")
|
| 20 |
+
else:
|
| 21 |
+
sns.countplot(data=df, x=x_col, ax=ax)
|
| 22 |
+
ax.set_title(f"Count plot of {x_col}")
|
| 23 |
+
else:
|
| 24 |
+
# Only x column, plot histogram or countplot
|
| 25 |
+
if pd.api.types.is_numeric_dtype(df[x_col]):
|
| 26 |
+
sns.histplot(df[x_col], ax=ax, kde=True)
|
| 27 |
+
ax.set_title(f"Histogram of {x_col}")
|
| 28 |
+
else:
|
| 29 |
+
sns.countplot(data=df, x=x_col, ax=ax)
|
| 30 |
+
ax.set_title(f"Count plot of {x_col}")
|
| 31 |
+
buf = io.BytesIO()
|
| 32 |
+
plt.savefig(buf, format='png')
|
| 33 |
+
buf.seek(0)
|
| 34 |
+
plots.append(buf)
|
| 35 |
+
plt.close(fig)
|
| 36 |
+
return [plot.getvalue() for plot in plots]
|
| 37 |
+
|
| 38 |
+
with gr.Blocks() as demo:
|
| 39 |
+
file_input = gr.File(label="Upload XLSX file")
|
| 40 |
+
col_dropdown = gr.Dropdown(label="Choose X variable")
|
| 41 |
+
y_col_dropdown = gr.Dropdown(label="Choose Y variable (optional)", interactive=True)
|
| 42 |
+
plot_output = gr.Gallery(label="Plot output")
|
| 43 |
+
|
| 44 |
+
df_state = gr.State()
|
| 45 |
+
|
| 46 |
+
def update_dropdowns(file):
|
| 47 |
+
if file is None:
|
| 48 |
+
return [], [], None
|
| 49 |
+
df = pd.read_excel(file.name)
|
| 50 |
+
cols = df.columns.tolist()
|
| 51 |
+
return gr.Dropdown.update(choices=cols), gr.Dropdown.update(choices=cols), df
|
| 52 |
+
|
| 53 |
+
file_input.change(update_dropdowns, inputs=file_input, outputs=[col_dropdown, y_col_dropdown, df_state])
|
| 54 |
+
|
| 55 |
+
def update_plot(x_col, y_col, df):
|
| 56 |
+
if df is None or x_col is None:
|
| 57 |
+
return []
|
| 58 |
+
return plot_chosen_columns(df, x_col, y_col)
|
| 59 |
+
|
| 60 |
+
col_dropdown.change(update_plot, inputs=[col_dropdown, y_col_dropdown, df_state], outputs=plot_output)
|
| 61 |
+
y_col_dropdown.change(update_plot, inputs=[col_dropdown, y_col_dropdown, df_state], outputs=plot_output)
|
| 62 |
+
|
| 63 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
matplotlib
|
| 4 |
+
seaborn
|
| 5 |
+
openpyxl
|