Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
# Load the Iris dataset | |
iris_df = sns.load_dataset('iris') | |
# Function to plot histogram | |
def plot_histogram(csv_file, column): | |
# Read the CSV file | |
custom_df = pd.read_csv(csv_file) | |
# Plot histogram | |
plt.figure(figsize=(8, 6)) | |
sns.histplot(custom_df[column]) | |
plt.title(f'Histogram for {column}') | |
plt.xlabel(column) | |
plt.ylabel('Frequency') | |
return plt | |
# Function to plot scatter plot | |
def plot_scatter(csv_file, x_axis, y_axis): | |
# Read the CSV file | |
custom_df = pd.read_csv(csv_file) | |
# Plot scatter plot | |
plt.figure(figsize=(8, 6)) | |
sns.scatterplot(x=x_axis, y=y_axis, data=custom_df) | |
plt.title(f'Scatter Plot ({x_axis} vs {y_axis})') | |
plt.xlabel(x_axis) | |
plt.ylabel(y_axis) | |
return plt | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=plot_histogram, | |
inputs=["csv", "text"], | |
outputs="plot", | |
title="Histogram Plotter", | |
description="Upload a CSV file and select a column to plot its histogram." | |
) | |
# Add a second interface for scatter plot | |
scatter_iface = gr.Interface( | |
fn=plot_scatter, | |
inputs=["csv", "text", "text"], | |
outputs="plot", | |
title="Scatter Plotter", | |
description="Upload a CSV file and select X and Y columns to plot a scatter plot." | |
) | |
# Launch the Gradio interfaces | |
iface.launch(share=True) | |
scatter_iface.launch(share=True) | |