Update app.py
Browse files
app.py
CHANGED
|
@@ -992,87 +992,6 @@ def refresh_data():
|
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
-
|
| 996 |
-
# λ¨Όμ target_datasets λμ
λ리λ₯Ό μΆκ°ν©λλ€
|
| 997 |
-
target_datasets = {
|
| 998 |
-
"aiqtech/kolaw": "https://huggingface.co/datasets/aiqtech/kolaw",
|
| 999 |
-
# μΆκ° λ°μ΄ν°μ
μ μ¬κΈ°μ κ³μ μΆκ°ν μ μμ΅λλ€
|
| 1000 |
-
}
|
| 1001 |
-
|
| 1002 |
-
def get_datasets_data(progress=gr.Progress()):
|
| 1003 |
-
"""λ°μ΄ν°μ
λ°μ΄ν° κ°μ Έμ€κΈ°"""
|
| 1004 |
-
def calculate_rank(dataset_id, all_global_datasets, korea_datasets):
|
| 1005 |
-
# κΈλ‘λ² μμ νμΈ
|
| 1006 |
-
global_rank = next((idx for idx, d in enumerate(all_global_datasets, 1)
|
| 1007 |
-
if d.get('id', '').strip() == dataset_id.strip()), None)
|
| 1008 |
-
|
| 1009 |
-
# Korea λ°μ΄ν°μ
μΈ κ²½μ°
|
| 1010 |
-
is_korea = any(d.get('id', '').strip() == dataset_id.strip() for d in korea_datasets)
|
| 1011 |
-
|
| 1012 |
-
if is_korea:
|
| 1013 |
-
# Korea λ°μ΄ν°μ
μ€μμμ μμ νμΈ
|
| 1014 |
-
korea_rank = next((idx for idx, d in enumerate(korea_datasets, 1)
|
| 1015 |
-
if d.get('id', '').strip() == dataset_id.strip()), None)
|
| 1016 |
-
|
| 1017 |
-
if korea_rank:
|
| 1018 |
-
return min(global_rank or 3001, korea_rank + 1000), True
|
| 1019 |
-
|
| 1020 |
-
return global_rank if global_rank else 'Not in top 3000', is_korea
|
| 1021 |
-
|
| 1022 |
-
try:
|
| 1023 |
-
progress(0, desc="Fetching datasets...")
|
| 1024 |
-
|
| 1025 |
-
if not HF_TOKEN:
|
| 1026 |
-
fig = create_error_plot()
|
| 1027 |
-
error_html = """
|
| 1028 |
-
<div style='padding: 20px; background: #fee; border-radius: 10px; margin: 10px 0;'>
|
| 1029 |
-
<h3 style='color: #c00;'>β οΈ API μΈμ¦μ΄ νμν©λλ€</h3>
|
| 1030 |
-
<p>HuggingFace API ν ν°μ΄ μ€μ λμ§ μμμ΅λλ€.</p>
|
| 1031 |
-
</div>
|
| 1032 |
-
"""
|
| 1033 |
-
empty_df = pd.DataFrame(columns=['Global Rank', 'Dataset ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
|
| 1034 |
-
return fig, error_html, empty_df
|
| 1035 |
-
|
| 1036 |
-
# μΌλ° λ°μ΄ν°μ
κ³Ό Korea κ΄λ ¨ λ°μ΄ν°μ
κ°μ Έμ€κΈ°
|
| 1037 |
-
params = {
|
| 1038 |
-
'limit': 3000,
|
| 1039 |
-
'full': 'true'
|
| 1040 |
-
}
|
| 1041 |
-
|
| 1042 |
-
all_datasets_response = requests.get(
|
| 1043 |
-
"https://huggingface.co/api/datasets",
|
| 1044 |
-
headers={'Authorization': f'Bearer {HF_TOKEN}'},
|
| 1045 |
-
params=params
|
| 1046 |
-
)
|
| 1047 |
-
|
| 1048 |
-
korea_params = {
|
| 1049 |
-
'search': 'korea',
|
| 1050 |
-
'limit': 3000,
|
| 1051 |
-
'full': 'true'
|
| 1052 |
-
}
|
| 1053 |
-
|
| 1054 |
-
korea_datasets_response = requests.get(
|
| 1055 |
-
"https://huggingface.co/api/datasets",
|
| 1056 |
-
headers={'Authorization': f'Bearer {HF_TOKEN}'},
|
| 1057 |
-
params=korea_params
|
| 1058 |
-
)
|
| 1059 |
-
|
| 1060 |
-
all_global_datasets = all_datasets_response.json()
|
| 1061 |
-
korea_datasets = korea_datasets_response.json()
|
| 1062 |
-
|
| 1063 |
-
# μκ°νλ₯Ό μν Figure μμ±
|
| 1064 |
-
fig = go.Figure()
|
| 1065 |
-
|
| 1066 |
-
# μμ μ 보 μμ§
|
| 1067 |
-
filtered_datasets = []
|
| 1068 |
-
for dataset_id in target_datasets.keys():
|
| 1069 |
-
try:
|
| 1070 |
-
normalized_id = dataset_id.strip('/')
|
| 1071 |
-
dataset_url_api = f"https://huggingface.co/api/datasets/{normalized_id}"
|
| 1072 |
-
response# λ¨Όμ target_datasets λμ
λ리λ₯Ό μΆκ°ν©λλ€
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
target_datasets = {
|
| 1077 |
"aiqtech/kolaw": "https://huggingface.co/datasets/aiqtech/kolaw",
|
| 1078 |
"heegyu/korquad-v1-v2": "https://huggingface.co/datasets/heegyu/korquad-v1-v2",
|
|
@@ -1089,8 +1008,6 @@ target_datasets = {
|
|
| 1089 |
}
|
| 1090 |
|
| 1091 |
def get_datasets_data(progress=gr.Progress()):
|
| 1092 |
-
try:
|
| 1093 |
-
|
| 1094 |
def calculate_rank(dataset_id, all_global_datasets, korea_datasets):
|
| 1095 |
# κΈλ‘λ² μμ νμΈ
|
| 1096 |
global_rank = next((idx for idx, d in enumerate(all_global_datasets, 1)
|
|
@@ -1100,7 +1017,6 @@ def get_datasets_data(progress=gr.Progress()):
|
|
| 1100 |
is_korea = any(d.get('id', '').strip() == dataset_id.strip() for d in korea_datasets)
|
| 1101 |
|
| 1102 |
if is_korea:
|
| 1103 |
-
# Korea λ°μ΄ν°μ
μ€μμμ μμ νμΈ
|
| 1104 |
korea_rank = next((idx for idx, d in enumerate(korea_datasets, 1)
|
| 1105 |
if d.get('id', '').strip() == dataset_id.strip()), None)
|
| 1106 |
|
|
@@ -1283,7 +1199,9 @@ def get_datasets_data(progress=gr.Progress()):
|
|
| 1283 |
|
| 1284 |
progress(1.0, desc="Complete!")
|
| 1285 |
|
|
|
|
| 1286 |
return fig, html_content, df
|
|
|
|
| 1287 |
except Exception as e:
|
| 1288 |
print(f"Error in get_datasets_data: {str(e)}")
|
| 1289 |
error_fig = create_error_plot()
|
|
@@ -1296,7 +1214,7 @@ def get_datasets_data(progress=gr.Progress()):
|
|
| 1296 |
empty_df = pd.DataFrame(columns=['Global Rank', 'Dataset ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
|
| 1297 |
return error_fig, error_html, empty_df
|
| 1298 |
|
| 1299 |
-
|
| 1300 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 1301 |
gr.Markdown("""
|
| 1302 |
# π€ νκΉ
νμ΄μ€ 'νκ΅(μΈμ΄) 리λ보λ'
|
|
@@ -1345,13 +1263,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 1345 |
datasets_results = get_datasets_data()
|
| 1346 |
|
| 1347 |
trending_plot.value, trending_info.value, trending_df.value = spaces_results
|
| 1348 |
-
models_plot.value,
|
| 1349 |
-
|
| 1350 |
-
|
| 1351 |
|
| 1352 |
# Gradio μ± μ€ν
|
| 1353 |
demo.launch(
|
| 1354 |
server_name="0.0.0.0",
|
| 1355 |
server_port=7860,
|
| 1356 |
share=False
|
| 1357 |
-
)
|
|
|
|
| 992 |
|
| 993 |
|
| 994 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 995 |
target_datasets = {
|
| 996 |
"aiqtech/kolaw": "https://huggingface.co/datasets/aiqtech/kolaw",
|
| 997 |
"heegyu/korquad-v1-v2": "https://huggingface.co/datasets/heegyu/korquad-v1-v2",
|
|
|
|
| 1008 |
}
|
| 1009 |
|
| 1010 |
def get_datasets_data(progress=gr.Progress()):
|
|
|
|
|
|
|
| 1011 |
def calculate_rank(dataset_id, all_global_datasets, korea_datasets):
|
| 1012 |
# κΈλ‘λ² μμ νμΈ
|
| 1013 |
global_rank = next((idx for idx, d in enumerate(all_global_datasets, 1)
|
|
|
|
| 1017 |
is_korea = any(d.get('id', '').strip() == dataset_id.strip() for d in korea_datasets)
|
| 1018 |
|
| 1019 |
if is_korea:
|
|
|
|
| 1020 |
korea_rank = next((idx for idx, d in enumerate(korea_datasets, 1)
|
| 1021 |
if d.get('id', '').strip() == dataset_id.strip()), None)
|
| 1022 |
|
|
|
|
| 1199 |
|
| 1200 |
progress(1.0, desc="Complete!")
|
| 1201 |
|
| 1202 |
+
|
| 1203 |
return fig, html_content, df
|
| 1204 |
+
|
| 1205 |
except Exception as e:
|
| 1206 |
print(f"Error in get_datasets_data: {str(e)}")
|
| 1207 |
error_fig = create_error_plot()
|
|
|
|
| 1214 |
empty_df = pd.DataFrame(columns=['Global Rank', 'Dataset ID', 'Title', 'Downloads', 'Likes', 'Korea Search', 'URL'])
|
| 1215 |
return error_fig, error_html, empty_df
|
| 1216 |
|
| 1217 |
+
|
| 1218 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 1219 |
gr.Markdown("""
|
| 1220 |
# π€ νκΉ
νμ΄μ€ 'νκ΅(μΈμ΄) 리λ보λ'
|
|
|
|
| 1263 |
datasets_results = get_datasets_data()
|
| 1264 |
|
| 1265 |
trending_plot.value, trending_info.value, trending_df.value = spaces_results
|
| 1266 |
+
models_plot.value, models_info.value, models_df.value = models_results
|
| 1267 |
+
datasets_plot.value, datasets_info.value, datasets_df.value = datasets_results
|
|
|
|
| 1268 |
|
| 1269 |
# Gradio μ± μ€ν
|
| 1270 |
demo.launch(
|
| 1271 |
server_name="0.0.0.0",
|
| 1272 |
server_port=7860,
|
| 1273 |
share=False
|
| 1274 |
+
)
|