Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -122,7 +122,7 @@ class ManualChatbot:
|
|
| 122 |
continue
|
| 123 |
|
| 124 |
# ファイル拡張子を確認
|
| 125 |
-
filename = file.name
|
| 126 |
file_ext = os.path.splitext(filename)[1].lower()
|
| 127 |
|
| 128 |
if file_ext not in ['.pdf', '.xlsx', '.xls', '.png', '.jpg', '.jpeg']:
|
|
@@ -190,6 +190,7 @@ class ManualChatbot:
|
|
| 190 |
embedding=embeddings,
|
| 191 |
persist_directory="./chroma_db"
|
| 192 |
)
|
|
|
|
| 193 |
else:
|
| 194 |
# 既存のベクトルストアに新しいドキュメントを追加
|
| 195 |
self.vectorstore.add_documents(chunks)
|
|
@@ -236,7 +237,7 @@ class ManualChatbot:
|
|
| 236 |
"""Excelファイルを処理してドキュメントを返す"""
|
| 237 |
try:
|
| 238 |
# Pandas でExcelを読み込む
|
| 239 |
-
dfs = pd.read_excel(file_path, sheet_name=None)
|
| 240 |
documents = []
|
| 241 |
|
| 242 |
for sheet_name, df in dfs.items():
|
|
@@ -375,7 +376,7 @@ class ManualChatbot:
|
|
| 375 |
return "チャットボットがまだ初期化されていません。ファイルをアップロードしてください。", ""
|
| 376 |
|
| 377 |
try:
|
| 378 |
-
result = self.qa_chain.invoke({"query": question})
|
| 379 |
|
| 380 |
# 回答の取得
|
| 381 |
if "result" in result:
|
|
|
|
| 122 |
continue
|
| 123 |
|
| 124 |
# ファイル拡張子を確認
|
| 125 |
+
filename = getattr(file, "orig_name", os.path.basename(file.name)) #file.name
|
| 126 |
file_ext = os.path.splitext(filename)[1].lower()
|
| 127 |
|
| 128 |
if file_ext not in ['.pdf', '.xlsx', '.xls', '.png', '.jpg', '.jpeg']:
|
|
|
|
| 190 |
embedding=embeddings,
|
| 191 |
persist_directory="./chroma_db"
|
| 192 |
)
|
| 193 |
+
self.vectorstore.persist()
|
| 194 |
else:
|
| 195 |
# 既存のベクトルストアに新しいドキュメントを追加
|
| 196 |
self.vectorstore.add_documents(chunks)
|
|
|
|
| 237 |
"""Excelファイルを処理してドキュメントを返す"""
|
| 238 |
try:
|
| 239 |
# Pandas でExcelを読み込む
|
| 240 |
+
dfs = pd.read_excel(file_path, sheet_name=None, engine="openpyxl" if file_path.endswith(".xlsx") else "xlrd")
|
| 241 |
documents = []
|
| 242 |
|
| 243 |
for sheet_name, df in dfs.items():
|
|
|
|
| 376 |
return "チャットボットがまだ初期化されていません。ファイルをアップロードしてください。", ""
|
| 377 |
|
| 378 |
try:
|
| 379 |
+
result = self.qa_chain.invoke({"question": question}) #({"query": question})
|
| 380 |
|
| 381 |
# 回答の取得
|
| 382 |
if "result" in result:
|