Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ import shutil # 用於文件複製
|
|
14 |
# 獲取 OpenAI API 密鑰
|
15 |
api_key = os.getenv("OPENAI_API_KEY")
|
16 |
if not api_key:
|
17 |
-
raise ValueError("未能獲取
|
18 |
openai.api_key = api_key
|
19 |
print("OpenAI API 密鑰已設置。")
|
20 |
|
@@ -145,11 +145,11 @@ def process_files(files, state):
|
|
145 |
try:
|
146 |
print(f"Received {len(files)} files")
|
147 |
saved_file_paths = []
|
148 |
-
for
|
149 |
-
print(f"Processing file: {
|
150 |
-
save_path = os.path.join(VECTORDB_DIR,
|
151 |
-
|
152 |
-
|
153 |
# 確認文件是否存在
|
154 |
if os.path.exists(save_path):
|
155 |
print(f"File successfully saved to: {save_path}")
|
@@ -194,7 +194,7 @@ with gr.Blocks() as demo:
|
|
194 |
file_types=[".pdf"],
|
195 |
label="上傳 PDF 文件",
|
196 |
interactive=True,
|
197 |
-
type="
|
198 |
)
|
199 |
upload_btn = gr.Button("上傳並處理")
|
200 |
upload_status = gr.Textbox(label="上傳狀態", interactive=False)
|
|
|
14 |
# 獲取 OpenAI API 密鑰
|
15 |
api_key = os.getenv("OPENAI_API_KEY")
|
16 |
if not api_key:
|
17 |
+
raise ValueError("未能獲取 OPENAI_API_KEY。請在 Hugging Face Spaces 的 Secrets 中設置它。")
|
18 |
openai.api_key = api_key
|
19 |
print("OpenAI API 密鑰已設置。")
|
20 |
|
|
|
145 |
try:
|
146 |
print(f"Received {len(files)} files")
|
147 |
saved_file_paths = []
|
148 |
+
for file in files:
|
149 |
+
print(f"Processing file: {file.name}")
|
150 |
+
save_path = os.path.join(VECTORDB_DIR, file.name)
|
151 |
+
with open(save_path, "wb") as f:
|
152 |
+
f.write(file.read())
|
153 |
# 確認文件是否存在
|
154 |
if os.path.exists(save_path):
|
155 |
print(f"File successfully saved to: {save_path}")
|
|
|
194 |
file_types=[".pdf"],
|
195 |
label="上傳 PDF 文件",
|
196 |
interactive=True,
|
197 |
+
type="file" # 修改為 'file'
|
198 |
)
|
199 |
upload_btn = gr.Button("上傳並處理")
|
200 |
upload_status = gr.Textbox(label="上傳狀態", interactive=False)
|