tori29umai commited on
Commit
7773d18
·
verified ·
1 Parent(s): d2d29d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -228,13 +228,16 @@ def upload_ini(file):
228
  return "ファイルがアップロードされていません。"
229
 
230
  try:
231
- content = file.decode('utf-8')
232
- except AttributeError:
233
- # ファイルが既にテキスト形式の場合
234
- content = file
235
 
236
  config = configparser.ConfigParser()
237
- config.read_string(content)
 
 
 
238
 
239
  if 'Settings' not in config:
240
  return "無効なINIファイルです。"
@@ -325,7 +328,7 @@ with gr.Blocks(css=custom_css) as iface:
325
  save_ini_output = gr.File(label="保存されたINIファイル")
326
 
327
  # INIファイルをアップロードして読み込むボタン
328
- upload_ini_button = gr.File(label="INIファイルをアップロード", type="text")
329
  upload_ini_output = gr.Textbox(label="アップロード状態")
330
 
331
  # INIファイルをローカルに保存する関数
 
228
  return "ファイルがアップロードされていません。"
229
 
230
  try:
231
+ with open(file.name, 'r', encoding='utf-8') as f:
232
+ content = f.read()
233
+ except Exception as e:
234
+ return f"ファイルの読み込み中にエラーが発生しました: {str(e)}"
235
 
236
  config = configparser.ConfigParser()
237
+ try:
238
+ config.read_string(content)
239
+ except configparser.Error:
240
+ return "無効なINIファイルです。"
241
 
242
  if 'Settings' not in config:
243
  return "無効なINIファイルです。"
 
328
  save_ini_output = gr.File(label="保存されたINIファイル")
329
 
330
  # INIファイルをアップロードして読み込むボタン
331
+ upload_ini_button = gr.File(label="INIファイルをアップロード", file_types=[".ini"])
332
  upload_ini_output = gr.Textbox(label="アップロード状態")
333
 
334
  # INIファイルをローカルに保存する関数