Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import tempfile
|
|
| 6 |
import os
|
| 7 |
from pathlib import Path
|
| 8 |
import re
|
|
|
|
| 9 |
|
| 10 |
def clean_json_content(content: str) -> str:
|
| 11 |
"""JSON λ¬Έμμ΄μμ μ£Όμμ μ κ±°νκ³ JSON νμμ μ 리ν©λλ€."""
|
|
@@ -65,18 +66,14 @@ def process_json_files(files: List[tempfile._TemporaryFileWrapper]) -> tuple[str
|
|
| 65 |
df = pd.DataFrame(all_data)
|
| 66 |
df_deduplicated = df.drop_duplicates(subset=['repo'])
|
| 67 |
|
| 68 |
-
#
|
| 69 |
-
|
| 70 |
-
temp_dir.mkdir(parents=True, exist_ok=True)
|
| 71 |
-
|
| 72 |
-
# κ²°κ³Όλ₯Ό μμ JSON νμΌλ‘ μ μ₯
|
| 73 |
-
output_path = temp_dir / "deduplicated_data.json"
|
| 74 |
result_json = df_deduplicated.to_dict('records')
|
| 75 |
|
| 76 |
with open(output_path, 'w', encoding='utf-8') as f:
|
| 77 |
json.dump(result_json, f, ensure_ascii=False, indent=2)
|
| 78 |
|
| 79 |
-
return
|
| 80 |
|
| 81 |
except Exception as e:
|
| 82 |
return None, f"μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
|
@@ -99,25 +96,23 @@ def create_example_file():
|
|
| 99 |
}
|
| 100 |
]
|
| 101 |
|
| 102 |
-
|
| 103 |
-
temp_dir.mkdir(parents=True, exist_ok=True)
|
| 104 |
-
example_path = temp_dir / "example.json"
|
| 105 |
|
| 106 |
with open(example_path, 'w', encoding='utf-8') as f:
|
| 107 |
json.dump(example_data, f, ensure_ascii=False, indent=2)
|
| 108 |
|
| 109 |
-
return
|
| 110 |
|
| 111 |
# Gradio μΈν°νμ΄μ€ μμ±
|
| 112 |
iface = gr.Interface(
|
| 113 |
fn=process_json_files,
|
| 114 |
inputs=gr.File(file_count="multiple", label="JSON νμΌ μ
λ‘λ (μ¬λ¬ κ° κ°λ₯)"),
|
| 115 |
outputs=[
|
| 116 |
-
gr.File(label="
|
| 117 |
gr.Textbox(label="μ²λ¦¬ κ²°κ³Ό")
|
| 118 |
],
|
| 119 |
title="JSON νμΌ μ€λ³΅ μ κ±° λꡬ",
|
| 120 |
-
description="repo κ°μ κΈ°μ€μΌλ‘ μ€λ³΅μ μ κ±°ν
|
| 121 |
examples=[[create_example_file()]]
|
| 122 |
)
|
| 123 |
|
|
|
|
| 6 |
import os
|
| 7 |
from pathlib import Path
|
| 8 |
import re
|
| 9 |
+
import shutil
|
| 10 |
|
| 11 |
def clean_json_content(content: str) -> str:
|
| 12 |
"""JSON λ¬Έμμ΄μμ μ£Όμμ μ κ±°νκ³ JSON νμμ μ 리ν©λλ€."""
|
|
|
|
| 66 |
df = pd.DataFrame(all_data)
|
| 67 |
df_deduplicated = df.drop_duplicates(subset=['repo'])
|
| 68 |
|
| 69 |
+
# κ²°κ³Όλ₯Ό loras.json νμΌλ‘ μ μ₯
|
| 70 |
+
output_path = "loras.json"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
result_json = df_deduplicated.to_dict('records')
|
| 72 |
|
| 73 |
with open(output_path, 'w', encoding='utf-8') as f:
|
| 74 |
json.dump(result_json, f, ensure_ascii=False, indent=2)
|
| 75 |
|
| 76 |
+
return output_path, f"μ±κ³΅μ μΌλ‘ μ²λ¦¬λμμ΅λλ€. μ€λ³΅ μ κ±° μ {len(all_data)}κ°, μ€λ³΅ μ κ±° ν {len(df_deduplicated)}κ°μ νλͺ©μ΄ μμ΅λλ€."
|
| 77 |
|
| 78 |
except Exception as e:
|
| 79 |
return None, f"μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
|
|
|
| 96 |
}
|
| 97 |
]
|
| 98 |
|
| 99 |
+
example_path = "example_loras.json"
|
|
|
|
|
|
|
| 100 |
|
| 101 |
with open(example_path, 'w', encoding='utf-8') as f:
|
| 102 |
json.dump(example_data, f, ensure_ascii=False, indent=2)
|
| 103 |
|
| 104 |
+
return example_path
|
| 105 |
|
| 106 |
# Gradio μΈν°νμ΄μ€ μμ±
|
| 107 |
iface = gr.Interface(
|
| 108 |
fn=process_json_files,
|
| 109 |
inputs=gr.File(file_count="multiple", label="JSON νμΌ μ
λ‘λ (μ¬λ¬ κ° κ°λ₯)"),
|
| 110 |
outputs=[
|
| 111 |
+
gr.File(label="loras.json λ€μ΄λ‘λ"),
|
| 112 |
gr.Textbox(label="μ²λ¦¬ κ²°κ³Ό")
|
| 113 |
],
|
| 114 |
title="JSON νμΌ μ€λ³΅ μ κ±° λꡬ",
|
| 115 |
+
description="repo κ°μ κΈ°μ€μΌλ‘ μ€λ³΅μ μ κ±°ν loras.json νμΌμ μμ±ν©λλ€.\nμ£Όμμ΄λ λΆμμ ν JSON νμλ μ²λ¦¬ κ°λ₯ν©λλ€.",
|
| 116 |
examples=[[create_example_file()]]
|
| 117 |
)
|
| 118 |
|