Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import seaborn as sns
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Load dataset automatically from GitHub
|
| 7 |
+
CSV_URL = "https://raw.githubusercontent.com/datablist/sample-csv-files/main/files/people/people-100.csv"
|
| 8 |
+
|
| 9 |
+
def load_data():
|
| 10 |
+
df = pd.read_csv(CSV_URL)
|
| 11 |
+
return df.head(10)
|
| 12 |
+
|
| 13 |
+
def visualize_data(column_x, column_y):
|
| 14 |
+
df = pd.read_csv(CSV_URL)
|
| 15 |
+
plt.figure(figsize=(7, 5))
|
| 16 |
+
sns.scatterplot(x=df[column_x], y=df[column_y])
|
| 17 |
+
plt.title(f"Scatter Plot: {column_x} vs {column_y}")
|
| 18 |
+
plt.tight_layout()
|
| 19 |
+
return plt.gcf()
|
| 20 |
+
|
| 21 |
+
def get_column_names():
|
| 22 |
+
df = pd.read_csv(CSV_URL)
|
| 23 |
+
return list(df.columns)
|
| 24 |
+
|
| 25 |
+
# Dropdown options
|
| 26 |
+
cols = get_column_names()
|
| 27 |
+
|
| 28 |
+
# Gradio interface
|
| 29 |
+
with gr.Blocks(title="CSV Visualizer using Gradio") as demo:
|
| 30 |
+
gr.Markdown("# 📊 CSV Visualizer\nUpload from GitHub and Explore the Data!")
|
| 31 |
+
|
| 32 |
+
with gr.Tab("View Data"):
|
| 33 |
+
view_btn = gr.Button("Load Data")
|
| 34 |
+
data_output = gr.Dataframe(label="Data Preview")
|
| 35 |
+
view_btn.click(load_data, outputs=data_output)
|
| 36 |
+
|
| 37 |
+
with gr.Tab("Visualize Data"):
|
| 38 |
+
x_col = gr.Dropdown(choices=cols, label="Select X-axis Column")
|
| 39 |
+
y_col = gr.Dropdown(choices=cols, label="Select Y-axis Column")
|
| 40 |
+
plot_btn = gr.Button("Generate Plot")
|
| 41 |
+
plot_output = gr.Plot(label="Visualization Output")
|
| 42 |
+
|
| 43 |
+
plot_btn.click(visualize_data, inputs=[x_col, y_col], outputs=plot_output)
|
| 44 |
+
|
| 45 |
+
# Launch app
|
| 46 |
+
demo.launch()
|