Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
def visualize_data(df): | |
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(20, 16)) | |
# スクロール深度とクリック率の関係 | |
sns.scatterplot(data=df, x='スクロール深度', y='クリック率', ax=ax1) | |
ax1.set_title('スクロール深度とクリック率の関係') | |
ax1.set_xlabel('スクロール深度') | |
ax1.set_ylabel('クリック率') | |
# クリック率の分布 | |
sns.boxplot(data=df, y='クリック率', ax=ax2) | |
ax2.set_title('クリック率の分布') | |
# 離脱率の分布 | |
sns.histplot(data=df, x='離脱率', kde=True, ax=ax3) | |
ax3.set_title('離脱率の分布') | |
# クリック数の分布 | |
sns.histplot(data=df, x='クリック数', kde=True, ax=ax4) | |
ax4.set_title('クリック数の分布') | |
plt.tight_layout() | |
return fig | |
def process_input(file): | |
df = pd.read_csv(file.name) | |
visualization_plot = visualize_data(df) | |
# データの概要を文字列として取得 | |
data_summary = df.describe().to_string() | |
return visualization_plot, data_summary | |
iface = gr.Interface( | |
fn=process_input, | |
inputs=[ | |
gr.File(label="CSVファイルをアップロード") | |
], | |
outputs=[ | |
gr.Plot(label="データ可視化"), | |
gr.Textbox(label="データ概要", lines=10) | |
], | |
title="リスティング広告LPデータの可視化", | |
description="CSVデータをアップロードして、データの可視化と概要を表示します。" | |
) | |
if __name__ == "__main__": | |
iface.launch() |