File size: 1,448 Bytes
21bd1c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)