Spaces:
Sleeping
Sleeping
File size: 5,893 Bytes
a005c19 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
import gradio as gr
from pathlib import Path
from leaderboard_ui.tab.submit_tab import submit_tab
from leaderboard_ui.tab.leaderboard_tab import leaderboard_tab
abs_path = Path(__file__).parent
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
import numpy as np
from utils.bench_meta import process_videos_in_directory
# Mock 데이터 생성
def create_mock_data():
benchmarks = ['VQA-2023', 'ImageQuality-2024', 'VideoEnhance-2024']
categories = ['Animation', 'Game', 'Movie', 'Sports', 'Vlog']
data_list = []
for benchmark in benchmarks:
n_videos = np.random.randint(50, 100)
for _ in range(n_videos):
category = np.random.choice(categories)
data_list.append({
"video_name": f"video_{np.random.randint(1000, 9999)}.mp4",
"resolution": np.random.choice(["1920x1080", "3840x2160", "1280x720"]),
"video_duration": f"{np.random.randint(0, 10)}:{np.random.randint(0, 60)}",
"category": category,
"benchmark": benchmark,
"duration_seconds": np.random.randint(30, 600),
"total_frames": np.random.randint(1000, 10000),
"file_format": ".mp4",
"file_size_mb": round(np.random.uniform(10, 1000), 2),
"aspect_ratio": 16/9,
"fps": np.random.choice([24, 30, 60])
})
return pd.DataFrame(data_list)
# Mock 데이터 생성
# df = process_videos_in_directory("/home/piawsa6000/nas192/videos/huggingface_benchmarks_dataset/Leaderboard_bench")
df = pd.read_csv("sample.csv")
print("DataFrame shape:", df.shape)
print("DataFrame columns:", df.columns)
print("DataFrame head:\n", df.head())
def create_category_pie_chart(df, selected_benchmark, selected_categories=None):
filtered_df = df[df['benchmark'] == selected_benchmark]
if selected_categories:
filtered_df = filtered_df[filtered_df['category'].isin(selected_categories)]
category_counts = filtered_df['category'].value_counts()
fig = px.pie(
values=category_counts.values,
names=category_counts.index,
title=f'{selected_benchmark} - Video Distribution by Category',
hole=0.3
)
fig.update_traces(textposition='inside', textinfo='percent+label')
return fig
###TODO 스트링일경우 어케 처리
def create_bar_chart(df, selected_benchmark, selected_categories, selected_column):
# Filter by benchmark and categories
filtered_df = df[df['benchmark'] == selected_benchmark]
if selected_categories:
filtered_df = filtered_df[filtered_df['category'].isin(selected_categories)]
# Create bar chart for selected column
fig = px.bar(
filtered_df,
x=selected_column,
y='video_name',
color='category', # Color by category
title=f'{selected_benchmark} - Video {selected_column}',
orientation='h', # Horizontal bar chart
color_discrete_sequence=px.colors.qualitative.Set3 # Color palette
)
# Adjust layout
fig.update_layout(
height=max(400, len(filtered_df) * 30), # Adjust height based on data
yaxis={'categoryorder': 'total ascending'}, # Sort by value
margin=dict(l=200), # Margin for long video names
showlegend=True, # Show legend
legend=dict(
orientation="h", # Horizontal legend
yanchor="bottom",
y=1.02, # Place legend above graph
xanchor="right",
x=1
)
)
return fig
def submit_tab():
with gr.Tab("🚀 Submit here! "):
with gr.Row():
gr.Markdown("# ✉️✨ Submit your Result here!")
def visual_tab():
with gr.Tab("📊 Bench Info"):
with gr.Row():
benchmark_dropdown = gr.Dropdown(
choices=sorted(df['benchmark'].unique().tolist()),
value=sorted(df['benchmark'].unique().tolist())[0],
label="Select Benchmark",
interactive=True
)
category_multiselect = gr.CheckboxGroup(
choices=sorted(df['category'].unique().tolist()),
label="Select Categories (empty for all)",
interactive=True
)
# Pie chart
pie_plot_output = gr.Plot(label="pie")
# Column selection dropdown
column_options = [
"video_duration", "duration_seconds", "total_frames",
"file_size_mb", "aspect_ratio", "fps", "file_format"
]
column_dropdown = gr.Dropdown(
choices=column_options,
value=column_options[0],
label="Select Data to Compare",
interactive=True
)
# Bar chart
bar_plot_output = gr.Plot(label="video")
def update_plots(benchmark, categories, selected_column):
pie_chart = create_category_pie_chart(df, benchmark, categories)
bar_chart = create_bar_chart(df, benchmark, categories, selected_column)
return pie_chart, bar_chart
# Connect event handlers
benchmark_dropdown.change(
fn=update_plots,
inputs=[benchmark_dropdown, category_multiselect, column_dropdown],
outputs=[pie_plot_output, bar_plot_output]
)
category_multiselect.change(
fn=update_plots,
inputs=[benchmark_dropdown, category_multiselect, column_dropdown],
outputs=[pie_plot_output, bar_plot_output]
)
column_dropdown.change(
fn=update_plots,
inputs=[benchmark_dropdown, category_multiselect, column_dropdown],
outputs=[pie_plot_output, bar_plot_output]
)
|