openfree commited on
Commit
486004a
β€’
1 Parent(s): c26f143

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +139 -133
app.py CHANGED
@@ -1,49 +1,45 @@
 
1
  import requests
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
  from datetime import datetime, timedelta
6
- import numpy as np
7
- import streamlit as st
8
  import plotly.graph_objects as go
9
- import plotly.express as px
10
- from PIL import Image
11
- import io
12
- import base64
13
-
14
- # νŽ˜μ΄μ§€ μ„€μ •
15
- st.set_page_config(layout="wide", page_title="HuggingFace Spaces Trending Analysis")
16
-
17
- # μŠ€νƒ€μΌ 적용
18
- st.markdown("""
19
- <style>
20
- .main {
21
- background-color: #f5f5f5;
22
- }
23
- .stButton>button {
24
- background-color: #ff4b4b;
25
- color: white;
26
- border-radius: 5px;
27
- }
28
- .trending-card {
29
- padding: 20px;
30
- border-radius: 10px;
31
- background-color: white;
32
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
33
- margin: 10px 0;
34
- }
35
- </style>
36
- """, unsafe_allow_html=True)
37
-
38
- # 타이틀
39
- st.title("πŸ€— HuggingFace Spaces Trending Analysis")
40
 
41
  # 관심 슀페이슀 URL λ¦¬μŠ€νŠΈμ™€ 정보
42
  target_spaces = {
43
  "ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama",
44
  "ginipick/SORA-3D": "https://huggingface.co/spaces/ginipick/SORA-3D",
45
  "fantaxy/Sound-AI-SFX": "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
46
- # ... [λ‚˜λ¨Έμ§€ μŠ€νŽ˜μ΄μŠ€λ“€λ„ λ™μΌν•œ ν˜•μ‹μœΌλ‘œ μΆ”κ°€]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  "NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
48
  }
49
 
@@ -60,9 +56,7 @@ def get_space_rank(spaces, space_id):
60
  return idx
61
  return None
62
 
63
- # 데이터 μˆ˜μ§‘
64
- @st.cache_data
65
- def fetch_trending_data():
66
  start_date = datetime(2023, 12, 1)
67
  end_date = datetime(2023, 12, 31)
68
  dates = [(start_date + timedelta(days=x)).strftime('%Y-%m-%d')
@@ -71,107 +65,119 @@ def fetch_trending_data():
71
  trending_data = {}
72
  target_space_ranks = {space: [] for space in target_spaces.keys()}
73
 
74
- with st.spinner('데이터λ₯Ό λΆˆλŸ¬μ˜€λŠ” 쀑...'):
75
- for date in dates:
76
- spaces = get_trending_spaces(date)
77
- if spaces:
78
- trending_data[date] = spaces
79
- for space_id in target_spaces.keys():
80
- rank = get_space_rank(spaces, space_id)
81
- target_space_ranks[space_id].append(rank)
82
 
83
  return trending_data, target_space_ranks, dates
84
 
85
- trending_data, target_space_ranks, dates = fetch_trending_data()
86
-
87
- # μ‹œκ°ν™”
88
- st.header("πŸ“ˆ Trending Rank Changes")
89
-
90
- # Plotlyλ₯Ό μ‚¬μš©ν•œ μΈν„°λž™ν‹°λΈŒ κ·Έλž˜ν”„
91
- fig = go.Figure()
92
-
93
- for space_id, ranks in target_space_ranks.items():
94
- fig.add_trace(go.Scatter(
95
- x=dates,
96
- y=ranks,
97
- name=space_id,
98
- mode='lines+markers',
99
- hovertemplate=
100
- '<b>Date</b>: %{x}<br>' +
101
- '<b>Rank</b>: %{y}<br>' +
102
- '<b>Space</b>: ' + space_id
103
- ))
104
-
105
- fig.update_layout(
106
- title='Trending Ranks Over Time',
107
- xaxis_title='Date',
108
- yaxis_title='Rank',
109
- yaxis_autorange='reversed',
110
- height=800,
111
- template='plotly_white',
112
- hovermode='x unified'
113
- )
114
-
115
- st.plotly_chart(fig, use_container_width=True)
116
-
117
- # μ΅œμ‹  μˆœμœ„ 정보 좜λ ₯
118
- st.header("πŸ† Latest Rankings")
119
-
120
- latest_date = max(trending_data.keys())
121
- latest_spaces = trending_data[latest_date]
122
-
123
- cols = st.columns(3)
124
- col_idx = 0
125
-
126
- for space_id, url in target_spaces.items():
127
- rank = get_space_rank(latest_spaces, space_id)
128
- if rank:
129
- space_info = next((s for s in latest_spaces if s['id'] == space_id), None)
130
- if space_info:
131
- with cols[col_idx % 3]:
132
- with st.container():
133
- st.markdown(f"""
134
- <div class="trending-card">
135
- <h3>#{rank} - {space_id}</h3>
136
- <p>πŸ‘ Likes: {space_info.get('likes', 'N/A')}</p>
137
- <p>πŸ“ {space_info.get('title', 'N/A')}</p>
138
- <p>{space_info.get('description', 'N/A')[:100]}...</p>
139
- <a href="{url}" target="_blank">Visit Space πŸ”—</a>
140
- </div>
141
- """, unsafe_allow_html=True)
142
- col_idx += 1
143
-
144
- # λ‹€μš΄λ‘œλ“œ κΈ°λŠ₯
145
- st.header("πŸ“Š Download Data")
146
 
147
- # DataFrame 생성
148
- df_data = []
149
- for date in dates:
150
- spaces = trending_data.get(date, [])
151
- for space_id in target_spaces.keys():
152
- rank = get_space_rank(spaces, space_id)
 
 
 
153
  if rank:
154
- space_info = next((s for s in spaces if s['id'] == space_id), None)
155
  if space_info:
156
- df_data.append({
157
- 'Date': date,
158
- 'Space ID': space_id,
159
- 'Rank': rank,
160
- 'Likes': space_info.get('likes', 'N/A'),
161
- 'Title': space_info.get('title', 'N/A'),
162
- 'URL': target_spaces[space_id]
163
- })
164
-
165
- df = pd.DataFrame(df_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
- # CSV λ‹€μš΄λ‘œλ“œ λ²„νŠΌ
168
- csv = df.to_csv(index=False)
169
- b64 = base64.b64encode(csv.encode()).decode()
170
- href = f'<a href="data:file/csv;base64,{b64}" download="trending_data.csv">Download CSV File</a>'
171
- st.markdown(href, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
172
 
173
- # ν‘Έν„°
174
- st.markdown("""
175
- ---
176
- Made with ❀️ using Streamlit and HuggingFace API
177
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  import requests
3
  import pandas as pd
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
6
  from datetime import datetime, timedelta
 
 
7
  import plotly.graph_objects as go
8
+ import numpy as np
9
+ import json
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  # 관심 슀페이슀 URL λ¦¬μŠ€νŠΈμ™€ 정보
12
  target_spaces = {
13
  "ginipick/FLUXllama": "https://huggingface.co/spaces/ginipick/FLUXllama",
14
  "ginipick/SORA-3D": "https://huggingface.co/spaces/ginipick/SORA-3D",
15
  "fantaxy/Sound-AI-SFX": "https://huggingface.co/spaces/fantaxy/Sound-AI-SFX",
16
+ "fantos/flx8lora": "https://huggingface.co/spaces/fantos/flx8lora",
17
+ "ginigen/Canvas": "https://huggingface.co/spaces/ginigen/Canvas",
18
+ "fantaxy/erotica": "https://huggingface.co/spaces/fantaxy/erotica",
19
+ "ginipick/time-machine": "https://huggingface.co/spaces/ginipick/time-machine",
20
+ "aiqcamp/FLUX-VisionReply": "https://huggingface.co/spaces/aiqcamp/FLUX-VisionReply",
21
+ "openfree/Tetris-Game": "https://huggingface.co/spaces/openfree/Tetris-Game",
22
+ "openfree/everychat": "https://huggingface.co/spaces/openfree/everychat",
23
+ "VIDraft/mouse1": "https://huggingface.co/spaces/VIDraft/mouse1",
24
+ "kolaslab/alpha-go": "https://huggingface.co/spaces/kolaslab/alpha-go",
25
+ "ginipick/text3d": "https://huggingface.co/spaces/ginipick/text3d",
26
+ "openfree/trending-board": "https://huggingface.co/spaces/openfree/trending-board",
27
+ "cutechicken/tankwar": "https://huggingface.co/spaces/cutechicken/tankwar",
28
+ "openfree/game-jewel": "https://huggingface.co/spaces/openfree/game-jewel",
29
+ "VIDraft/mouse-chat": "https://huggingface.co/spaces/VIDraft/mouse-chat",
30
+ "ginipick/AccDiffusion": "https://huggingface.co/spaces/ginipick/AccDiffusion",
31
+ "aiqtech/Particle-Accelerator-Simulation": "https://huggingface.co/spaces/aiqtech/Particle-Accelerator-Simulation",
32
+ "openfree/GiniGEN": "https://huggingface.co/spaces/openfree/GiniGEN",
33
+ "kolaslab/3DAudio-Spectrum-Analyzer": "https://huggingface.co/spaces/kolaslab/3DAudio-Spectrum-Analyzer",
34
+ "openfree/trending-news-24": "https://huggingface.co/spaces/openfree/trending-news-24",
35
+ "ginipick/Realtime-FLUX": "https://huggingface.co/spaces/ginipick/Realtime-FLUX",
36
+ "VIDraft/prime-number": "https://huggingface.co/spaces/VIDraft/prime-number",
37
+ "kolaslab/zombie-game": "https://huggingface.co/spaces/kolaslab/zombie-game",
38
+ "fantos/miro-game": "https://huggingface.co/spaces/fantos/miro-game",
39
+ "kolaslab/shooting": "https://huggingface.co/spaces/kolaslab/shooting",
40
+ "VIDraft/Mouse-Hackathon": "https://huggingface.co/spaces/VIDraft/Mouse-Hackathon",
41
+ "upstage/open-ko-llm-leaderboard": "https://huggingface.co/spaces/upstage/open-ko-llm-leaderboard",
42
+ "LGAI-EXAONE/EXAONE-3.5-Instruct-Demo": "https://huggingface.co/spaces/LGAI-EXAONE/EXAONE-3.5-Instruct-Demo",
43
  "NCSOFT/VARCO_Arena": "https://huggingface.co/spaces/NCSOFT/VARCO_Arena"
44
  }
45
 
 
56
  return idx
57
  return None
58
 
59
+ def fetch_and_analyze_data():
 
 
60
  start_date = datetime(2023, 12, 1)
61
  end_date = datetime(2023, 12, 31)
62
  dates = [(start_date + timedelta(days=x)).strftime('%Y-%m-%d')
 
65
  trending_data = {}
66
  target_space_ranks = {space: [] for space in target_spaces.keys()}
67
 
68
+ for date in dates:
69
+ spaces = get_trending_spaces(date)
70
+ if spaces:
71
+ trending_data[date] = spaces
72
+ for space_id in target_spaces.keys():
73
+ rank = get_space_rank(spaces, space_id)
74
+ target_space_ranks[space_id].append(rank)
 
75
 
76
  return trending_data, target_space_ranks, dates
77
 
78
+ def create_trend_plot(trending_data, target_space_ranks, dates):
79
+ fig = go.Figure()
80
+
81
+ for space_id, ranks in target_space_ranks.items():
82
+ fig.add_trace(go.Scatter(
83
+ x=dates,
84
+ y=ranks,
85
+ name=space_id,
86
+ mode='lines+markers'
87
+ ))
88
+
89
+ fig.update_layout(
90
+ title='Trending Ranks Over Time',
91
+ xaxis_title='Date',
92
+ yaxis_title='Rank',
93
+ yaxis_autorange='reversed',
94
+ height=800
95
+ )
96
+
97
+ return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
+ def create_space_info_html(trending_data):
100
+ latest_date = max(trending_data.keys())
101
+ latest_spaces = trending_data[latest_date]
102
+
103
+ html_content = "<div style='padding: 20px;'>"
104
+ html_content += f"<h2>Latest Rankings ({latest_date})</h2>"
105
+
106
+ for space_id, url in target_spaces.items():
107
+ rank = get_space_rank(latest_spaces, space_id)
108
  if rank:
109
+ space_info = next((s for s in latest_spaces if s['id'] == space_id), None)
110
  if space_info:
111
+ html_content += f"""
112
+ <div style='margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 8px;'>
113
+ <h3>#{rank} - {space_id}</h3>
114
+ <p>πŸ‘ Likes: {space_info.get('likes', 'N/A')}</p>
115
+ <p>πŸ“ {space_info.get('title', 'N/A')}</p>
116
+ <p>{space_info.get('description', 'N/A')[:100]}...</p>
117
+ <a href='{url}' target='_blank' style='color: blue;'>Visit Space πŸ”—</a>
118
+ </div>
119
+ """
120
+
121
+ html_content += "</div>"
122
+ return html_content
123
+
124
+ def export_data(trending_data, dates):
125
+ df_data = []
126
+ for date in dates:
127
+ spaces = trending_data.get(date, [])
128
+ for space_id in target_spaces.keys():
129
+ rank = get_space_rank(spaces, space_id)
130
+ if rank:
131
+ space_info = next((s for s in spaces if s['id'] == space_id), None)
132
+ if space_info:
133
+ df_data.append({
134
+ 'Date': date,
135
+ 'Space ID': space_id,
136
+ 'Rank': rank,
137
+ 'Likes': space_info.get('likes', 'N/A'),
138
+ 'Title': space_info.get('title', 'N/A'),
139
+ 'URL': target_spaces[space_id]
140
+ })
141
+
142
+ df = pd.DataFrame(df_data)
143
+ return df
144
 
145
+ def main_interface():
146
+ trending_data, target_space_ranks, dates = fetch_and_analyze_data()
147
+
148
+ # νŠΈλ Œλ“œ ν”Œλ‘― 생성
149
+ plot = create_trend_plot(trending_data, target_space_ranks, dates)
150
+
151
+ # 슀페이슀 정보 HTML 생성
152
+ space_info = create_space_info_html(trending_data)
153
+
154
+ # 데이터 읡슀포트
155
+ df = export_data(trending_data, dates)
156
+
157
+ return plot, space_info, df
158
 
159
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ 생성
160
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
161
+ gr.Markdown("# πŸ€— HuggingFace Spaces Trending Analysis")
162
+
163
+ with gr.Tab("Trending Analysis"):
164
+ plot_output = gr.Plot()
165
+ info_output = gr.HTML()
166
+
167
+ with gr.Tab("Export Data"):
168
+ df_output = gr.DataFrame()
169
+
170
+ refresh_btn = gr.Button("Refresh Data")
171
+ refresh_btn.click(
172
+ main_interface,
173
+ outputs=[plot_output, info_output, df_output]
174
+ )
175
+
176
+ # 초기 데이터 λ‘œλ“œ
177
+ plot, info, df = main_interface()
178
+ plot_output.update(value=plot)
179
+ info_output.update(value=info)
180
+ df_output.update(value=df)
181
+
182
+ # Gradio μ•± μ‹€ν–‰
183
+ demo.launch()