Spaces:
Sleeping
Sleeping
Update excel_chat.py
Browse files- excel_chat.py +14 -0
excel_chat.py
CHANGED
|
@@ -219,7 +219,10 @@ def chat_with_mistral(source_cols, dest_col, prompt, excel_file, url, search_col
|
|
| 219 |
|
| 220 |
filtred_df = filter_df(df, search_col, keywords)
|
| 221 |
|
|
|
|
| 222 |
cpt = 1
|
|
|
|
|
|
|
| 223 |
for index, row in filtred_df.iterrows():
|
| 224 |
concatenated_content = "\n\n".join(f"{column_name}: {str(row[column_name])}" for column_name in source_cols)
|
| 225 |
if not concatenated_content == "\n\n".join(f"{column_name}: nan" for column_name in source_cols):
|
|
@@ -227,15 +230,26 @@ def chat_with_mistral(source_cols, dest_col, prompt, excel_file, url, search_col
|
|
| 227 |
try:
|
| 228 |
llm_answer,gloabal_keys = ask_llm(prompt[0], concatenated_content, client, user, gloabal_keys)
|
| 229 |
except Exception:
|
|
|
|
| 230 |
llm_answer = "unhandled global error"
|
| 231 |
|
| 232 |
print(f"{cpt}/{len(filtred_df)}\nQUERY:\n{prompt[0]}\nCONTENT:\n{concatenated_content[:200]}...\n\nANSWER:\n{llm_answer}")
|
| 233 |
df.at[index, dest_col] = llm_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
cpt += 1
|
| 235 |
# progress((index+1)/len(df),desc=f'Request {index+1}/{len(df)}')
|
| 236 |
|
| 237 |
df.to_excel(file_name, index=False)
|
| 238 |
|
|
|
|
|
|
|
| 239 |
zip_file_path = 'config_file.zip'
|
| 240 |
|
| 241 |
with zipfile.ZipFile(zip_file_path, 'w') as zipf:
|
|
|
|
| 219 |
|
| 220 |
filtred_df = filter_df(df, search_col, keywords)
|
| 221 |
|
| 222 |
+
checkpoints_files = []
|
| 223 |
cpt = 1
|
| 224 |
+
blop = 50
|
| 225 |
+
len(fitered_df) // 4
|
| 226 |
for index, row in filtred_df.iterrows():
|
| 227 |
concatenated_content = "\n\n".join(f"{column_name}: {str(row[column_name])}" for column_name in source_cols)
|
| 228 |
if not concatenated_content == "\n\n".join(f"{column_name}: nan" for column_name in source_cols):
|
|
|
|
| 230 |
try:
|
| 231 |
llm_answer,gloabal_keys = ask_llm(prompt[0], concatenated_content, client, user, gloabal_keys)
|
| 232 |
except Exception:
|
| 233 |
+
print("Catched a error : Global exception for ask_llm")
|
| 234 |
llm_answer = "unhandled global error"
|
| 235 |
|
| 236 |
print(f"{cpt}/{len(filtred_df)}\nQUERY:\n{prompt[0]}\nCONTENT:\n{concatenated_content[:200]}...\n\nANSWER:\n{llm_answer}")
|
| 237 |
df.at[index, dest_col] = llm_answer
|
| 238 |
+
|
| 239 |
+
if cpt == blop:
|
| 240 |
+
df.to_excel(str(cpt))
|
| 241 |
+
checkpoints_files.append(str(cpt))
|
| 242 |
+
|
| 243 |
+
blop += 50
|
| 244 |
+
|
| 245 |
+
|
| 246 |
cpt += 1
|
| 247 |
# progress((index+1)/len(df),desc=f'Request {index+1}/{len(df)}')
|
| 248 |
|
| 249 |
df.to_excel(file_name, index=False)
|
| 250 |
|
| 251 |
+
|
| 252 |
+
|
| 253 |
zip_file_path = 'config_file.zip'
|
| 254 |
|
| 255 |
with zipfile.ZipFile(zip_file_path, 'w') as zipf:
|