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ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama",
|
|
@@ -388,10 +531,11 @@ def refresh_data():
|
|
| 388 |
else:
|
| 389 |
return create_error_plot(), "<div>API μΈμ¦μ΄ νμν©λλ€.</div>", pd.DataFrame()
|
| 390 |
|
|
|
|
| 391 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 392 |
gr.Markdown("""
|
| 393 |
-
# π€ HuggingFace
|
| 394 |
-
μ€μκ°μΌλ‘ Hugging Face Spaces
|
| 395 |
""")
|
| 396 |
|
| 397 |
with gr.Tab("Trending Rankings"):
|
|
@@ -404,28 +548,37 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 404 |
modes_info = gr.HTML()
|
| 405 |
modes_df = gr.DataFrame()
|
| 406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
refresh_btn = gr.Button("π Refresh Data", variant="primary")
|
| 408 |
|
| 409 |
-
def
|
| 410 |
trending_results = get_spaces_data("trending")
|
| 411 |
modes_results = get_spaces_data("modes")
|
| 412 |
-
|
|
|
|
| 413 |
|
| 414 |
refresh_btn.click(
|
| 415 |
-
|
| 416 |
outputs=[
|
| 417 |
trending_plot, trending_info, trending_df,
|
| 418 |
-
modes_plot, modes_info, modes_df
|
|
|
|
| 419 |
]
|
| 420 |
)
|
| 421 |
|
| 422 |
# μ΄κΈ° λ°μ΄ν° λ‘λ
|
| 423 |
trending_results = get_spaces_data("trending")
|
| 424 |
modes_results = get_spaces_data("modes")
|
|
|
|
| 425 |
|
| 426 |
trending_plot.value, trending_info.value, trending_df.value = trending_results
|
| 427 |
modes_plot.value, modes_info.value, modes_df.value = modes_results
|
| 428 |
-
|
|
|
|
| 429 |
# Gradio μ± μ€ν
|
| 430 |
demo.launch(
|
| 431 |
server_name="0.0.0.0",
|
|
|
|
| 7 |
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
|
| 10 |
+
target_models = {
|
| 11 |
+
"openfree/flux-lora-korea-palace": "https://huggingface.co/openfree/flux-lora-korea-palace",
|
| 12 |
+
"seawolf2357/hanbok": "https://huggingface.co/seawolf2357/hanbok",
|
| 13 |
+
"LGAI-EXAONE/EXAONE-3.5-32B-Instruct": "https://huggingface.co/LGAI-EXAONE/EXAONE-3.5-32B-Instruct",
|
| 14 |
+
"LGAI-EXAONE/EXAONE-3.5-2.4B-Instruct": "https://huggingface.co/LGAI-EXAONE/EXAONE-3.5-2.4B-Instruct",
|
| 15 |
+
"LGAI-EXAONE/EXAONE-3.5-7.8B-Instruct": "https://huggingface.co/LGAI-EXAONE/EXAONE-3.5-7.8B-Instruct",
|
| 16 |
+
"ginipick/flux-lora-eric-cat": "https://huggingface.co/ginipick/flux-lora-eric-cat",
|
| 17 |
+
"seawolf2357/flux-lora-car-rolls-royce": "https://huggingface.co/seawolf2357/flux-lora-car-rolls-royce"
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
def get_models_data(sort_type="trending", progress=gr.Progress()):
|
| 21 |
+
"""λͺ¨λΈ λ°μ΄ν° κ°μ Έμ€κΈ°"""
|
| 22 |
+
url = "https://huggingface.co/api/models"
|
| 23 |
+
params = {
|
| 24 |
+
'full': 'true',
|
| 25 |
+
'limit': 1000, # μμ 1000κ° λͺ¨λΈ
|
| 26 |
+
'sort': 'downloads' if sort_type == "modes" else 'lastModified'
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
progress(0, desc=f"Fetching {sort_type} models data...")
|
| 31 |
+
response = requests.get(url, params=params)
|
| 32 |
+
response.raise_for_status()
|
| 33 |
+
all_models = response.json()
|
| 34 |
+
|
| 35 |
+
# μμ μ 보 μ μ₯
|
| 36 |
+
model_ranks = {model['id']: idx + 1 for idx, model in enumerate(all_models)}
|
| 37 |
+
|
| 38 |
+
# target_models νν°λ§ λ° μμ μ 보 ν¬ν¨
|
| 39 |
+
models = []
|
| 40 |
+
for model in all_models:
|
| 41 |
+
if model.get('id', '') in target_models:
|
| 42 |
+
model['rank'] = model_ranks.get(model['id'], 'N/A')
|
| 43 |
+
models.append(model)
|
| 44 |
+
|
| 45 |
+
# μμλ³λ‘ μ λ ¬
|
| 46 |
+
models.sort(key=lambda x: x['rank'])
|
| 47 |
+
|
| 48 |
+
progress(0.3, desc="Creating visualization...")
|
| 49 |
+
|
| 50 |
+
# μκ°ν μμ±
|
| 51 |
+
fig = go.Figure()
|
| 52 |
+
|
| 53 |
+
# λ°μ΄ν° μ€λΉ
|
| 54 |
+
ids = [model['id'] for model in models]
|
| 55 |
+
ranks = [model['rank'] for model in models]
|
| 56 |
+
downloads = [model.get('downloads', 0) for model in models]
|
| 57 |
+
|
| 58 |
+
# YμΆ κ°μ λ°μ (1000 - rank + 1)
|
| 59 |
+
y_values = [1001 - r for r in ranks]
|
| 60 |
+
|
| 61 |
+
# λ§λ κ·Έλν μμ±
|
| 62 |
+
fig.add_trace(go.Bar(
|
| 63 |
+
x=ids,
|
| 64 |
+
y=y_values,
|
| 65 |
+
text=[f"Rank: {r}<br>Downloads: {d}" for r, d in zip(ranks, downloads)],
|
| 66 |
+
textposition='auto',
|
| 67 |
+
marker_color='rgb(255,127,14)',
|
| 68 |
+
opacity=0.8
|
| 69 |
+
))
|
| 70 |
+
|
| 71 |
+
fig.update_layout(
|
| 72 |
+
title={
|
| 73 |
+
'text': f'Hugging Face Models {sort_type.title()} Rankings (Top 1000)',
|
| 74 |
+
'y':0.95,
|
| 75 |
+
'x':0.5,
|
| 76 |
+
'xanchor': 'center',
|
| 77 |
+
'yanchor': 'top'
|
| 78 |
+
},
|
| 79 |
+
xaxis_title='Model ID',
|
| 80 |
+
yaxis_title='Rank',
|
| 81 |
+
yaxis=dict(
|
| 82 |
+
ticktext=[str(i) for i in range(1, 1001, 50)],
|
| 83 |
+
tickvals=[1001 - i for i in range(1, 1001, 50)],
|
| 84 |
+
range=[0, 1000]
|
| 85 |
+
),
|
| 86 |
+
height=800,
|
| 87 |
+
showlegend=False,
|
| 88 |
+
template='plotly_white',
|
| 89 |
+
xaxis_tickangle=-45
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
progress(0.6, desc="Creating model cards...")
|
| 93 |
+
|
| 94 |
+
# HTML μΉ΄λ μμ±
|
| 95 |
+
html_content = f"""
|
| 96 |
+
<div style='padding: 20px; background: #f5f5f5;'>
|
| 97 |
+
<h2 style='color: #2c3e50;'>Model {sort_type.title()} Rankings</h2>
|
| 98 |
+
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
for model in models:
|
| 102 |
+
model_id = model.get('id', '')
|
| 103 |
+
rank = model.get('rank', 'N/A')
|
| 104 |
+
downloads = model.get('downloads', 0)
|
| 105 |
+
likes = model.get('likes', 0)
|
| 106 |
+
|
| 107 |
+
html_content += f"""
|
| 108 |
+
<div style='
|
| 109 |
+
background: white;
|
| 110 |
+
padding: 20px;
|
| 111 |
+
border-radius: 10px;
|
| 112 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 113 |
+
transition: transform 0.2s;
|
| 114 |
+
'>
|
| 115 |
+
<h3 style='color: #34495e;'>Rank #{rank} - {model_id}</h3>
|
| 116 |
+
<p style='color: #7f8c8d;'>β¬οΈ Downloads: {downloads}</p>
|
| 117 |
+
<p style='color: #7f8c8d;'>π Likes: {likes}</p>
|
| 118 |
+
<a href='{target_models[model_id]}'
|
| 119 |
+
target='_blank'
|
| 120 |
+
style='
|
| 121 |
+
display: inline-block;
|
| 122 |
+
padding: 8px 16px;
|
| 123 |
+
background: #e67e22;
|
| 124 |
+
color: white;
|
| 125 |
+
text-decoration: none;
|
| 126 |
+
border-radius: 5px;
|
| 127 |
+
transition: background 0.3s;
|
| 128 |
+
'>
|
| 129 |
+
Visit Model π
|
| 130 |
+
</a>
|
| 131 |
+
</div>
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
html_content += "</div></div>"
|
| 135 |
+
|
| 136 |
+
# λ°μ΄ν°νλ μ μμ±
|
| 137 |
+
df = pd.DataFrame([{
|
| 138 |
+
'Rank': model.get('rank', 'N/A'),
|
| 139 |
+
'Model ID': model.get('id', ''),
|
| 140 |
+
'Downloads': model.get('downloads', 'N/A'),
|
| 141 |
+
'Likes': model.get('likes', 'N/A'),
|
| 142 |
+
'URL': target_models[model.get('id', '')]
|
| 143 |
+
} for model in models])
|
| 144 |
+
|
| 145 |
+
progress(1.0, desc="Complete!")
|
| 146 |
+
return fig, html_content, df
|
| 147 |
+
|
| 148 |
+
except Exception as e:
|
| 149 |
+
error_html = f'<div style="color: red; padding: 20px;">Error: {str(e)}</div>'
|
| 150 |
+
error_plot = create_error_plot()
|
| 151 |
+
return error_plot, error_html, pd.DataFrame()
|
| 152 |
+
|
| 153 |
# κ΄μ¬ μ€νμ΄μ€ URL 리μ€νΈμ μ 보
|
| 154 |
target_spaces = {
|
| 155 |
"ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama",
|
|
|
|
| 531 |
else:
|
| 532 |
return create_error_plot(), "<div>API μΈμ¦μ΄ νμν©λλ€.</div>", pd.DataFrame()
|
| 533 |
|
| 534 |
+
|
| 535 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 536 |
gr.Markdown("""
|
| 537 |
+
# π€ HuggingFace Rankings Analysis
|
| 538 |
+
μ€μκ°μΌλ‘ Hugging Faceμ Spacesμ Models μμλ₯Ό λΆμν©λλ€.
|
| 539 |
""")
|
| 540 |
|
| 541 |
with gr.Tab("Trending Rankings"):
|
|
|
|
| 548 |
modes_info = gr.HTML()
|
| 549 |
modes_df = gr.DataFrame()
|
| 550 |
|
| 551 |
+
with gr.Tab("Models Rankings"):
|
| 552 |
+
models_plot = gr.Plot()
|
| 553 |
+
models_info = gr.HTML()
|
| 554 |
+
models_df = gr.DataFrame()
|
| 555 |
+
|
| 556 |
refresh_btn = gr.Button("π Refresh Data", variant="primary")
|
| 557 |
|
| 558 |
+
def refresh_all_data():
|
| 559 |
trending_results = get_spaces_data("trending")
|
| 560 |
modes_results = get_spaces_data("modes")
|
| 561 |
+
models_results = get_models_data("trending")
|
| 562 |
+
return [*trending_results, *modes_results, *models_results]
|
| 563 |
|
| 564 |
refresh_btn.click(
|
| 565 |
+
refresh_all_data,
|
| 566 |
outputs=[
|
| 567 |
trending_plot, trending_info, trending_df,
|
| 568 |
+
modes_plot, modes_info, modes_df,
|
| 569 |
+
models_plot, models_info, models_df
|
| 570 |
]
|
| 571 |
)
|
| 572 |
|
| 573 |
# μ΄κΈ° λ°μ΄ν° λ‘λ
|
| 574 |
trending_results = get_spaces_data("trending")
|
| 575 |
modes_results = get_spaces_data("modes")
|
| 576 |
+
models_results = get_models_data("trending")
|
| 577 |
|
| 578 |
trending_plot.value, trending_info.value, trending_df.value = trending_results
|
| 579 |
modes_plot.value, modes_info.value, modes_df.value = modes_results
|
| 580 |
+
models_plot.value, models_info.value, models_df.value = models_results
|
| 581 |
+
|
| 582 |
# Gradio μ± μ€ν
|
| 583 |
demo.launch(
|
| 584 |
server_name="0.0.0.0",
|