openfree's picture
Update app.py
ded31ce verified
raw
history blame
3.09 kB
import gradio as gr
import pandas as pd
import numpy as np
# ๋ฐ์ดํ„ฐ ์ •์˜ (ํ•˜๋“œ์ฝ”๋”ฉ)
data = {
"Company/Model": [
"Anthropic/Claude 3 Opus",
"OpenAI/GPT-4",
"Google/Gemini Ultra",
"Cohere/Command R+",
"Naver/HyperCLOVA X",
"Kakao/KoGPT"
],
"URL": [
"https://www.anthropic.com/claude",
"https://openai.com/gpt-4",
"https://deepmind.google/technologies/gemini/",
"https://cohere.com/models/command-r-plus",
"https://clova.ai/hyperclova",
"https://kogpt.ai/"
],
"Korean Bar Exam (๋ณ€ํ˜ธ์‚ฌ)": [85, 82, 80, 75, 79, 77],
"Senior Civil Service Examination (๊ตญ๊ฐ€์ง 5๊ธ‰)": [88, 84, 83, 76, 81, 78]
}
# DataFrame ์ƒ์„ฑ
df = pd.DataFrame(data)
# Average ์ ์ˆ˜ ๊ณ„์‚ฐ
exam_columns = ["Korean Bar Exam (๋ณ€ํ˜ธ์‚ฌ)", "Senior Civil Service Examination (๊ตญ๊ฐ€์ง 5๊ธ‰)"]
df["Average"] = df[exam_columns].mean(axis=1).round(1)
# ์—ด ์ˆœ์„œ ์žฌ๋ฐฐ์น˜ (Company/Model, URL, Average, ๊ทธ ๋‹ค์Œ ๊ฐ ์‹œํ—˜)
cols = ["Company/Model", "URL", "Average"] + exam_columns
df = df[cols]
# HTML๋กœ ๋ Œ๋”๋งํ•˜๊ธฐ ์œ„ํ•œ ํ•จ์ˆ˜ (URL์„ ํด๋ฆญ ๊ฐ€๋Šฅํ•œ ๋งํฌ๋กœ ๋ณ€ํ™˜)
def format_df_as_html(df):
# DataFrame ๋ณต์‚ฌ๋ณธ ์ƒ์„ฑ
display_df = df.copy()
# URL ์—ด์„ ํด๋ฆญ ๊ฐ€๋Šฅํ•œ ๋งํฌ๋กœ ๋ณ€ํ™˜
for i, url in enumerate(display_df["URL"]):
model_name = display_df.iloc[i]["Company/Model"]
display_df.at[i, "Company/Model"] = f'<a href="{url}" target="_blank">{model_name}</a>'
# URL ์—ด ์ œ๊ฑฐ (์ด๋ฏธ Company/Model์— ๋งํฌ๋กœ ํ†ตํ•ฉ)
display_df = display_df.drop("URL", axis=1)
# ํ‘œ ์Šคํƒ€์ผ ์ถ”๊ฐ€
styled_html = """
<style>
table {
width: 100%;
border-collapse: collapse;
font-family: Arial, sans-serif;
}
th {
background-color: #4CAF50;
color: white;
font-weight: bold;
text-align: left;
padding: 12px;
}
td {
padding: 10px;
border-bottom: 1px solid #ddd;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
.header {
text-align: center;
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
}
</style>
<div class="header">Korean Exam Leaderboard</div>
"""
# DataFrame์„ HTML๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ์Šคํƒ€์ผ ์ ์šฉ
html_table = display_df.to_html(index=False, escape=False)
return styled_html + html_table
# Gradio ์ธํ„ฐํŽ˜์ด์Šค
def show_leaderboard():
html_content = format_df_as_html(df)
return html_content
# ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
demo = gr.Interface(
fn=show_leaderboard,
inputs=None,
outputs=gr.HTML(),
title="Korean Exam Leaderboard",
description="์„ฑ๋Šฅ ๋น„๊ต: ํ•œ๊ตญ ๋ฒ•ํ•™ ๋ฐ ํ–‰์ •๊ณ ์‹œ ์‹œํ—˜์—์„œ์˜ AI ๋ชจ๋ธ ์ ์ˆ˜"
)
# ์•ฑ ์‹คํ–‰
if __name__ == "__main__":
demo.launch()