Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +66 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tempfile
|
| 3 |
+
import shutil
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import matplotlib.cm as cm
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import japanize_matplotlib
|
| 9 |
+
import numpy as np
|
| 10 |
+
import matplotlib.pyplot as plt
|
| 11 |
+
import seaborn as sns
|
| 12 |
+
|
| 13 |
+
def all_likelihood_plot(csv_file_name, tmpdir):
|
| 14 |
+
df = pd.read_csv(csv_file_name, header=[1, 2])
|
| 15 |
+
df = df.drop(df.columns[[0]], axis=1)
|
| 16 |
+
columns = df.columns.droplevel(1)
|
| 17 |
+
|
| 18 |
+
# 重複を削除
|
| 19 |
+
columns = columns.drop_duplicates()
|
| 20 |
+
likelihood = [df[x]["likelihood"] for x in columns]
|
| 21 |
+
a = pd.DataFrame(likelihood, index=columns).T
|
| 22 |
+
|
| 23 |
+
#平均値を求める
|
| 24 |
+
point_average = a.mean()
|
| 25 |
+
parts = ["指節1", "指節2", "指節3", "指節4", "指節5", "指節6", "指節7", "指節8", "指節9",
|
| 26 |
+
"指節10", "指節11", "指節12", "指節13", "指節14", "触角(右)", "触角(左)", "頭部", "腹尾節"]
|
| 27 |
+
|
| 28 |
+
# カラーマップの設定
|
| 29 |
+
a.columns = parts
|
| 30 |
+
cmap = plt.get_cmap('rainbow')
|
| 31 |
+
# バイオリン図のプロット
|
| 32 |
+
sns.set(style="whitegrid",font="IPAexGothic")
|
| 33 |
+
fig, ax = plt.subplots()
|
| 34 |
+
|
| 35 |
+
# データをバイオリンプロットで描画
|
| 36 |
+
sns.violinplot(data=a, palette=[cmap(i)
|
| 37 |
+
for i in np.linspace(0, 1, len(columns))], ax=ax,inner=None)
|
| 38 |
+
|
| 39 |
+
# 横軸のラベルを重ならないように
|
| 40 |
+
plt.xticks(rotation=65)
|
| 41 |
+
|
| 42 |
+
ax.set_title('付属肢別の尤度')
|
| 43 |
+
ax.set_xlabel('付属肢')
|
| 44 |
+
ax.set_ylabel('尤度')
|
| 45 |
+
|
| 46 |
+
#それぞれの要素の平均値をプロット
|
| 47 |
+
plt.scatter(x=parts, y=point_average, color='black', marker='x')
|
| 48 |
+
|
| 49 |
+
# 最大値を1に
|
| 50 |
+
plt.ylim(0, 1)
|
| 51 |
+
|
| 52 |
+
#ラベルがはみ出ないように
|
| 53 |
+
plt.tight_layout()
|
| 54 |
+
|
| 55 |
+
# グラフを表示
|
| 56 |
+
plt.savefig(f"likelihood.png", dpi=300)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def main(csv_file):
|
| 60 |
+
with tempfile.TemporaryDirectory(dir=".") as tmpdir:
|
| 61 |
+
all_likelihood_plot(csv_file, tmpdir)
|
| 62 |
+
return f"likelihood.png"
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
iface = gr.Interface(fn=main, inputs="file", outputs="image", title="尤度のグラフを作成します。")
|
| 66 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
matplotlib
|
| 3 |
+
numpy
|
| 4 |
+
japanize_matplotlib
|
| 5 |
+
seaborn
|