QIDNLF commited on
Commit
12e2a33
·
verified ·
1 Parent(s): 0dac90b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -5,7 +5,7 @@ import os
5
  import re
6
  import shutil
7
 
8
- # 1️⃣ 저장소 설정
9
  UPLOAD_DIR = "uploaded_dbs"
10
  if not os.path.exists(UPLOAD_DIR):
11
  os.makedirs(UPLOAD_DIR)
@@ -83,7 +83,7 @@ def update_category_dd(standard, version):
83
  except Exception as e:
84
  return gr.Dropdown(choices=["ALL"], value=None)
85
 
86
- # 3️⃣ 데이터 조회 로직 (컬럼 필터링 추가)
87
  def display_data(standard, version, selection):
88
  if not all([standard, version, selection]): return None
89
  try:
@@ -94,7 +94,7 @@ def display_data(standard, version, selection):
94
  main_t = f"{standard}_{version}"
95
  if main_t not in all_tables: main_t = all_tables[0]
96
 
97
- is_sub_table = False # 추가 테이블인지 확인용 플래그
98
 
99
  if selection == "ALL":
100
  df = pd.read_sql(f"SELECT * FROM [{main_t}]", conn)
@@ -111,17 +111,14 @@ def display_data(standard, version, selection):
111
  conn.close()
112
 
113
  if not df.empty:
114
- # 1. 정렬 적용
115
  sort_col = 'section' if 'section' in df.columns else df.columns[0]
116
  df['sort_key'] = df[sort_col].apply(natural_sort_key)
117
  df = df.sort_values(by='sort_key').drop(columns=['sort_key'])
118
 
119
- # 2. [추가 요구사항] 본문(ALL 또는 카테고리)일 때만 section, description만 남기기
120
  if not is_sub_table:
121
  available_cols = [c for c in ['section', 'description'] if c in df.columns]
122
  df = df[available_cols]
123
  else:
124
- # 추가 테이블일 경우 내부 정렬용 컬럼만 제거하고 전체 유지
125
  df = df[[c for c in df.columns if not c.startswith('sort_')]]
126
 
127
  return df
@@ -130,7 +127,7 @@ def display_data(standard, version, selection):
130
 
131
  # 4️⃣ UI 구성
132
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
133
- gr.Markdown("# 📜 Regulation ")
134
 
135
  with gr.Accordion("➕ DB 관리", open=False):
136
  file_input = gr.File(label="DB 업로드", file_count="multiple", file_types=[".db"])
@@ -151,5 +148,5 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
151
  category_dd.change(display_data, [standard_dd, version_dd, category_dd], output_df)
152
 
153
  if __name__ == "__main__":
154
-
155
- demo.launch(share=True)
 
5
  import re
6
  import shutil
7
 
8
+ # 1️⃣ 저장소 설정 (폴더 안에 DB를 모으기로 했으므로 유지)
9
  UPLOAD_DIR = "uploaded_dbs"
10
  if not os.path.exists(UPLOAD_DIR):
11
  os.makedirs(UPLOAD_DIR)
 
83
  except Exception as e:
84
  return gr.Dropdown(choices=["ALL"], value=None)
85
 
86
+ # 3️⃣ 데이터 조회 로직
87
  def display_data(standard, version, selection):
88
  if not all([standard, version, selection]): return None
89
  try:
 
94
  main_t = f"{standard}_{version}"
95
  if main_t not in all_tables: main_t = all_tables[0]
96
 
97
+ is_sub_table = False
98
 
99
  if selection == "ALL":
100
  df = pd.read_sql(f"SELECT * FROM [{main_t}]", conn)
 
111
  conn.close()
112
 
113
  if not df.empty:
 
114
  sort_col = 'section' if 'section' in df.columns else df.columns[0]
115
  df['sort_key'] = df[sort_col].apply(natural_sort_key)
116
  df = df.sort_values(by='sort_key').drop(columns=['sort_key'])
117
 
 
118
  if not is_sub_table:
119
  available_cols = [c for c in ['section', 'description'] if c in df.columns]
120
  df = df[available_cols]
121
  else:
 
122
  df = df[[c for c in df.columns if not c.startswith('sort_')]]
123
 
124
  return df
 
127
 
128
  # 4️⃣ UI 구성
129
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
130
+ gr.Markdown("# 📜 Regulation Viewer")
131
 
132
  with gr.Accordion("➕ DB 관리", open=False):
133
  file_input = gr.File(label="DB 업로드", file_count="multiple", file_types=[".db"])
 
148
  category_dd.change(display_data, [standard_dd, version_dd, category_dd], output_df)
149
 
150
  if __name__ == "__main__":
151
+ # 허깅페이스 배포 시에는 share=True가 필요 없으므로 제거합니다.
152
+ demo.launch()