tomo2chin2 commited on
Commit
64c24db
·
verified ·
1 Parent(s): e042c47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -66,13 +66,23 @@ def list_files_with_no(repo_type):
66
  except Exception as e:
67
  return [[f"エラー: ファイルリストの取得に失敗しました: {e}", None]]
68
 
69
- # 並び替え関数(No.列の順序に従う)
70
- def reorder_files(data):
71
  try:
72
- reordered_data = sorted(data, key=lambda x: int(x[0])) # No.列で並び替え
73
- return reordered_data
 
 
 
 
 
 
 
 
 
 
74
  except Exception as e:
75
- return data, f"並び替え中にエラーが発生しました: {e}"
76
 
77
  # Gradio UI構築
78
  with gr.Blocks() as demo:
@@ -93,15 +103,15 @@ with gr.Blocks() as demo:
93
  load_button.click(list_files_with_no, inputs=repo_choice, outputs=file_list_output)
94
 
95
  # 並び替えセクション
96
- gr.Markdown("### No.列を変更して並び替えを適用")
97
  reorder_button = gr.Button("並び替え適用")
98
  sorted_table = gr.Dataframe(headers=["No.", "Filename"], datatype=["number", "str"], interactive=False)
99
 
100
- def apply_reorder(data):
101
- reordered_data = reorder_files(data)
102
- return reordered_data, "並び替えが完了しました。"
103
 
104
- reorder_button.click(apply_reorder, inputs=file_list_output, outputs=[sorted_table, output])
105
 
106
  if __name__ == "__main__":
107
  demo.launch()
 
66
  except Exception as e:
67
  return [[f"エラー: ファイルリストの取得に失敗しました: {e}", None]]
68
 
69
+ # 並び替えをリポジトリに反映
70
+ def apply_reorder_to_repo(data, repo_type):
71
  try:
72
+ target_repo = MODEL_REPO if repo_type == "model" else LORA_REPO
73
+ if not target_repo:
74
+ return "エラー: リポジトリが設定されていません。"
75
+
76
+ # 並び替えられたファイルリストをリポジトリに反映 (例: ファイル順序を更新する処理を追加可能)
77
+ reordered_files = sorted(data, key=lambda x: int(x[0])) # No.列の順序に基づいて並び替え
78
+ reordered_filenames = [file[1] for file in reordered_files]
79
+
80
+ # Mock反映: 並び替えたファイル名を表示
81
+ # 実際のリポジトリ反映処理はAPIやスクリプトで実装
82
+ result_message = f"リポジトリ順序を以下の順に反映しました:\n" + "\n".join(reordered_filenames)
83
+ return reordered_files, result_message
84
  except Exception as e:
85
+ return data, f"リポジトリ更新中にエラーが発生しました: {e}"
86
 
87
  # Gradio UI構築
88
  with gr.Blocks() as demo:
 
103
  load_button.click(list_files_with_no, inputs=repo_choice, outputs=file_list_output)
104
 
105
  # 並び替えセクション
106
+ gr.Markdown("### No.列を変更して並び替えを適用し、リポジトリに反映")
107
  reorder_button = gr.Button("並び替え適用")
108
  sorted_table = gr.Dataframe(headers=["No.", "Filename"], datatype=["number", "str"], interactive=False)
109
 
110
+ def apply_reorder(data, repo_type):
111
+ reordered_data, message = apply_reorder_to_repo(data, repo_type)
112
+ return reordered_data, message
113
 
114
+ reorder_button.click(apply_reorder, inputs=[file_list_output, repo_choice], outputs=[sorted_table, output])
115
 
116
  if __name__ == "__main__":
117
  demo.launch()