openfree commited on
Commit
2b852a9
Β·
verified Β·
1 Parent(s): a99b8c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
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
- temp_dir = Path(tempfile.gettempdir()) / "json_dedup"
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 str(output_path), f"μ„±κ³΅μ μœΌλ‘œ μ²˜λ¦¬λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 쀑볡 제거 μ „ {len(all_data)}개, 쀑볡 제거 ν›„ {len(df_deduplicated)}개의 ν•­λͺ©μ΄ μžˆμŠ΅λ‹ˆλ‹€."
80
 
81
  except Exception as e:
82
  return None, f"처리 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
@@ -99,25 +96,23 @@ def create_example_file():
99
  }
100
  ]
101
 
102
- temp_dir = Path(tempfile.gettempdir()) / "json_dedup"
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 str(example_path)
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="처리된 JSON 파일 λ‹€μš΄λ‘œλ“œ"),
117
  gr.Textbox(label="처리 κ²°κ³Ό")
118
  ],
119
  title="JSON 파일 쀑볡 제거 도ꡬ",
120
- description="repo 값을 κΈ°μ€€μœΌλ‘œ 쀑볡을 μ œκ±°ν•œ JSON νŒŒμΌμ„ μƒμ„±ν•©λ‹ˆλ‹€.\nμ£Όμ„μ΄λ‚˜ λΆˆμ™„μ „ν•œ JSON ν˜•μ‹λ„ 처리 κ°€λŠ₯ν•©λ‹ˆλ‹€.",
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