Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
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.
|
128 |
-
character_files = gr.
|
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)
|
|
|
|