PSNbst commited on
Commit
e8a0f4d
·
verified ·
1 Parent(s): 2a19f55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -19,14 +19,10 @@ def load_candidates_from_files(files):
19
  all_lines = []
20
  if files:
21
  for file in files:
22
- # 如果 `file` 是路径
23
  if isinstance(file, str):
24
  with open(file, "r", encoding="utf-8") as f:
25
  all_lines.extend([line.strip() for line in f if line.strip()])
26
- # 如果 `file` 是 Gradio 的文件对象
27
- elif hasattr(file, "name"):
28
- with open(file.name, "r", encoding="utf-8") as f:
29
- all_lines.extend([line.strip() for line in f if line.strip()])
30
  return all_lines
31
 
32
  def get_random_item(candidates):
@@ -124,8 +120,8 @@ def gradio_interface():
124
  style_file = gr.File(label="Upload Style File (Optional)", file_types=[".txt"])
125
 
126
  with gr.Row():
127
- artist_files = gr.File(label="Upload Artist Files (Multiple Allowed)", file_types=[".txt"], multiple=True)
128
- character_files = gr.File(label="Upload Character Files (Multiple Allowed)", file_types=[".txt"], multiple=True)
129
 
130
  # 角色类型选择
131
  selected_categories = gr.CheckboxGroup(
@@ -152,6 +148,4 @@ def gradio_interface():
152
 
153
  # 启动 Gradio 应用
154
  if __name__ == "__main__":
155
- gradio_interface().launch(share=True)
156
-
157
-
 
19
  all_lines = []
20
  if files:
21
  for file in files:
22
+ # Gradio Files 返回文件路径
23
  if isinstance(file, str):
24
  with open(file, "r", encoding="utf-8") as f:
25
  all_lines.extend([line.strip() for line in f if line.strip()])
 
 
 
 
26
  return all_lines
27
 
28
  def get_random_item(candidates):
 
120
  style_file = gr.File(label="Upload Style File (Optional)", file_types=[".txt"])
121
 
122
  with gr.Row():
123
+ artist_files = gr.Files(label="Upload Artist Files (Multiple Allowed)", file_types=[".txt"])
124
+ character_files = gr.Files(label="Upload Character Files (Multiple Allowed)", file_types=[".txt"])
125
 
126
  # 角色类型选择
127
  selected_categories = gr.CheckboxGroup(
 
148
 
149
  # 启动 Gradio 应用
150
  if __name__ == "__main__":
151
+ gradio_interface().launch(share=True)