Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,55 +56,6 @@ def create_trend_chart(space_id, daily_ranks_df):
|
|
| 56 |
print(f"Error creating chart: {e}")
|
| 57 |
return None
|
| 58 |
|
| 59 |
-
def create_space_card(space_info):
|
| 60 |
-
# μμμ λ°λ₯Έ νμ€ν
μμ κ³μ°
|
| 61 |
-
hue = 210 # νλμ κ³μ΄
|
| 62 |
-
saturation = max(30, 90 - (space_info['rank'] / 100 * 60)) # μμκ° λμμλ‘ λ μ λͺ
ν μμ
|
| 63 |
-
lightness = min(97, 85 + (space_info['rank'] / 100 * 10)) # μμκ° λμμλ‘ λ λ°μ μμ
|
| 64 |
-
|
| 65 |
-
return f"""
|
| 66 |
-
<div class="space-card"
|
| 67 |
-
data-space-id="{space_info['id']}"
|
| 68 |
-
style="
|
| 69 |
-
border: 1px solid #e5e7eb;
|
| 70 |
-
border-radius: 8px;
|
| 71 |
-
padding: 16px;
|
| 72 |
-
margin: 8px;
|
| 73 |
-
background-color: hsl({hue}, {saturation}%, {lightness}%);
|
| 74 |
-
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 75 |
-
display: inline-block;
|
| 76 |
-
width: 250px;
|
| 77 |
-
vertical-align: top;
|
| 78 |
-
cursor: pointer;
|
| 79 |
-
transition: all 0.2s;
|
| 80 |
-
"
|
| 81 |
-
onmouseover="this.style.transform='translateY(-2px)';this.style.boxShadow='0 4px 6px rgba(0,0,0,0.1)';"
|
| 82 |
-
onmouseout="this.style.transform='none';this.style.boxShadow='0 1px 3px rgba(0,0,0,0.1)';"
|
| 83 |
-
>
|
| 84 |
-
<div style="font-size: 1.2em; font-weight: bold; margin-bottom: 8px;">
|
| 85 |
-
#{int(space_info['rank'])}
|
| 86 |
-
</div>
|
| 87 |
-
<div style="margin-bottom: 8px;">
|
| 88 |
-
{space_info['id']}
|
| 89 |
-
</div>
|
| 90 |
-
<div style="color: #666; margin-bottom: 12px;">
|
| 91 |
-
Score: {space_info['trendingScore']:.2f}
|
| 92 |
-
</div>
|
| 93 |
-
<div style="display: flex; gap: 8px;">
|
| 94 |
-
<a href="https://huggingface.co/spaces/{space_info['id']}"
|
| 95 |
-
target="_blank"
|
| 96 |
-
style="padding: 6px 12px; background-color: white; color: #2563eb; text-decoration: none; border-radius: 4px; font-size: 0.9em; border: 1px solid #2563eb;"
|
| 97 |
-
onclick="event.stopPropagation();">
|
| 98 |
-
View Space β
|
| 99 |
-
</a>
|
| 100 |
-
<button onclick="event.stopPropagation(); document.querySelector('input[type=\'radio\'][value=\'{space_info['id']}\']').click();"
|
| 101 |
-
style="padding: 6px 12px; background-color: #2563eb; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9em;">
|
| 102 |
-
View Trend
|
| 103 |
-
</button>
|
| 104 |
-
</div>
|
| 105 |
-
</div>
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
def update_display(selection):
|
| 109 |
global daily_ranks_df
|
| 110 |
|
|
@@ -196,7 +147,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 196 |
with gr.Row(variant="panel"):
|
| 197 |
trend_plot = gr.Plot(
|
| 198 |
label="Daily Rank Trend",
|
| 199 |
-
container=True
|
| 200 |
)
|
| 201 |
|
| 202 |
with gr.Row():
|
|
@@ -204,18 +155,76 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 204 |
value="<div style='text-align: center; padding: 20px; color: #666;'>Select a space to view details</div>"
|
| 205 |
)
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
with gr.Row():
|
| 208 |
-
space_grid = gr.HTML(
|
| 209 |
-
value="<div style='display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;'>" +
|
| 210 |
-
"".join([create_space_card(row) for _, row in top_100_spaces.iterrows()]) +
|
| 211 |
-
"</div>"
|
| 212 |
-
)
|
| 213 |
-
|
| 214 |
-
space_selection = gr.Radio(
|
| 215 |
-
choices=[row['id'] for _, row in top_100_spaces.iterrows()],
|
| 216 |
-
value=None,
|
| 217 |
-
visible=False
|
| 218 |
-
)
|
| 219 |
|
| 220 |
with gr.Tab("About"):
|
| 221 |
gr.Markdown("""
|
|
@@ -246,23 +255,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 246 |
Experience the pulse of the AI community through our daily updated rankings and discover what's making waves in the world of practical AI applications.
|
| 247 |
""")
|
| 248 |
|
| 249 |
-
#
|
| 250 |
-
space_grid.click(
|
| 251 |
-
None,
|
| 252 |
-
None,
|
| 253 |
-
None,
|
| 254 |
-
js="""async (event) => {
|
| 255 |
-
if (event.target.closest('.space-card')) {
|
| 256 |
-
const spaceId = event.target.closest('.space-card').dataset.spaceId;
|
| 257 |
-
document.querySelector(`input[type="radio"][value="${spaceId}"]`).click();
|
| 258 |
-
}
|
| 259 |
-
}"""
|
| 260 |
-
)
|
| 261 |
-
|
| 262 |
space_selection.change(
|
| 263 |
fn=update_display,
|
| 264 |
inputs=[space_selection],
|
| 265 |
-
outputs=[trend_plot, info_box]
|
|
|
|
| 266 |
)
|
| 267 |
|
| 268 |
if __name__ == "__main__":
|
|
|
|
| 56 |
print(f"Error creating chart: {e}")
|
| 57 |
return None
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def update_display(selection):
|
| 60 |
global daily_ranks_df
|
| 61 |
|
|
|
|
| 147 |
with gr.Row(variant="panel"):
|
| 148 |
trend_plot = gr.Plot(
|
| 149 |
label="Daily Rank Trend",
|
| 150 |
+
container=True,
|
| 151 |
)
|
| 152 |
|
| 153 |
with gr.Row():
|
|
|
|
| 155 |
value="<div style='text-align: center; padding: 20px; color: #666;'>Select a space to view details</div>"
|
| 156 |
)
|
| 157 |
|
| 158 |
+
# λΌλμ€ λ²νΌμ λ¨Όμ μ μ
|
| 159 |
+
space_selection = gr.Radio(
|
| 160 |
+
choices=[row['id'] for _, row in top_100_spaces.iterrows()],
|
| 161 |
+
value=None,
|
| 162 |
+
visible=False
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
# HTMLμμ JavaScript μ΄λ²€νΈλ₯Ό μ§μ μ²λ¦¬
|
| 166 |
+
html_content = """
|
| 167 |
+
<div style='display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;'>
|
| 168 |
+
""" + "".join([
|
| 169 |
+
f"""
|
| 170 |
+
<div class="space-card"
|
| 171 |
+
data-space-id="{row['id']}"
|
| 172 |
+
style="
|
| 173 |
+
border: 1px solid #e5e7eb;
|
| 174 |
+
border-radius: 8px;
|
| 175 |
+
padding: 16px;
|
| 176 |
+
margin: 8px;
|
| 177 |
+
background-color: hsl(210, {max(30, 90 - (row['rank'] / 100 * 60))}%, {min(97, 85 + (row['rank'] / 100 * 10))}%);
|
| 178 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 179 |
+
display: inline-block;
|
| 180 |
+
width: 250px;
|
| 181 |
+
vertical-align: top;
|
| 182 |
+
cursor: pointer;
|
| 183 |
+
transition: all 0.2s;
|
| 184 |
+
"
|
| 185 |
+
onmouseover="this.style.transform='translateY(-2px)';this.style.boxShadow='0 4px 6px rgba(0,0,0,0.1)';"
|
| 186 |
+
onmouseout="this.style.transform='none';this.style.boxShadow='0 1px 3px rgba(0,0,0,0.1)';"
|
| 187 |
+
>
|
| 188 |
+
<div style="font-size: 1.2em; font-weight: bold; margin-bottom: 8px;">
|
| 189 |
+
#{int(row['rank'])}
|
| 190 |
+
</div>
|
| 191 |
+
<div style="margin-bottom: 8px;">
|
| 192 |
+
{row['id']}
|
| 193 |
+
</div>
|
| 194 |
+
<div style="color: #666; margin-bottom: 12px;">
|
| 195 |
+
Score: {row['trendingScore']:.2f}
|
| 196 |
+
</div>
|
| 197 |
+
<div style="display: flex; gap: 8px;">
|
| 198 |
+
<a href="https://huggingface.co/spaces/{row['id']}"
|
| 199 |
+
target="_blank"
|
| 200 |
+
style="padding: 6px 12px; background-color: white; color: #2563eb; text-decoration: none; border-radius: 4px; font-size: 0.9em; border: 1px solid #2563eb;"
|
| 201 |
+
onclick="event.stopPropagation();">
|
| 202 |
+
View Space β
|
| 203 |
+
</a>
|
| 204 |
+
<button onclick="event.preventDefault(); gradioEvent('{row['id']}');"
|
| 205 |
+
style="padding: 6px 12px; background-color: #2563eb; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9em;">
|
| 206 |
+
View Trend
|
| 207 |
+
</button>
|
| 208 |
+
</div>
|
| 209 |
+
</div>
|
| 210 |
+
"""
|
| 211 |
+
for _, row in top_100_spaces.iterrows()
|
| 212 |
+
]) + """
|
| 213 |
+
</div>
|
| 214 |
+
<script>
|
| 215 |
+
function gradioEvent(spaceId) {
|
| 216 |
+
const radio = document.querySelector(`input[type="radio"][value="${spaceId}"]`);
|
| 217 |
+
if (radio) {
|
| 218 |
+
radio.checked = true;
|
| 219 |
+
const event = new Event('change');
|
| 220 |
+
radio.dispatchEvent(event);
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
</script>
|
| 224 |
+
"""
|
| 225 |
+
|
| 226 |
with gr.Row():
|
| 227 |
+
space_grid = gr.HTML(value=html_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
with gr.Tab("About"):
|
| 230 |
gr.Markdown("""
|
|
|
|
| 255 |
Experience the pulse of the AI community through our daily updated rankings and discover what's making waves in the world of practical AI applications.
|
| 256 |
""")
|
| 257 |
|
| 258 |
+
# λΌλμ€ λ²νΌ λ³κ²½ μ΄λ²€νΈ μ°κ²°
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
space_selection.change(
|
| 260 |
fn=update_display,
|
| 261 |
inputs=[space_selection],
|
| 262 |
+
outputs=[trend_plot, info_box],
|
| 263 |
+
api_name="update_display"
|
| 264 |
)
|
| 265 |
|
| 266 |
if __name__ == "__main__":
|