openfree commited on
Commit
6f65709
·
verified ·
1 Parent(s): 7735def

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import pandas as pd
4
+ from typing import List, Dict
5
+ import tempfile
6
+ import os
7
+
8
+ def process_json_files(files: List[tempfile._TemporaryFileWrapper]) -> str:
9
+ # 모든 JSON 데이터를 저장할 리스트
10
+ all_data = []
11
+
12
+ # 업로드된 각 파일 처리
13
+ for file in files:
14
+ try:
15
+ content = file.read().decode('utf-8')
16
+ json_data = json.loads(content)
17
+
18
+ # 단일 객체인 경우 리스트로 변환
19
+ if isinstance(json_data, dict):
20
+ json_data = [json_data]
21
+
22
+ all_data.extend(json_data)
23
+ except Exception as e:
24
+ return f"Error processing file {file.name}: {str(e)}"
25
+
26
+ # DataFrame으로 변환하여 중복 제거
27
+ df = pd.DataFrame(all_data)
28
+ df_deduplicated = df.drop_duplicates(subset=['repo'])
29
+
30
+ # 결과를 JSON 파일로 저장
31
+ output_path = "deduplicated_data.json"
32
+ result_json = df_deduplicated.to_dict('records')
33
+
34
+ with open(output_path, 'w', encoding='utf-8') as f:
35
+ json.dump(result_json, f, ensure_ascii=False, indent=2)
36
+
37
+ return output_path
38
+
39
+ # Gradio 인터페이스 생성
40
+ iface = gr.Interface(
41
+ fn=process_json_files,
42
+ inputs=gr.File(file_count="multiple", label="JSON 파일 업로드 (여러 개 가능)"),
43
+ outputs=gr.File(label="처리된 JSON 파일 다운로드"),
44
+ title="JSON 파일 중복 제거 도구",
45
+ description="repo 값을 기준으로 중복을 제거한 JSON 파일을 생성합니다.",
46
+ )
47
+
48
+ # 앱 실행
49
+ if __name__ == "__main__":
50
+ iface.launch()