openfree commited on
Commit
41d9eba
ยท
verified ยท
1 Parent(s): 5370608

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +160 -7
app.py CHANGED
@@ -7,6 +7,149 @@ import os
7
 
8
  HF_TOKEN = os.getenv("HF_TOKEN")
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # ๊ด€์‹ฌ ์ŠคํŽ˜์ด์Šค URL ๋ฆฌ์ŠคํŠธ์™€ ์ •๋ณด
11
  target_spaces = {
12
  "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 Spaces Rankings Analysis
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 refresh_data():
410
  trending_results = get_spaces_data("trending")
411
  modes_results = get_spaces_data("modes")
412
- return [*trending_results, *modes_results]
 
413
 
414
  refresh_btn.click(
415
- refresh_data,
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",