镜像自地址
https://github.com/binary-husky/gpt_academic.git
已同步 2025-12-06 14:36:48 +00:00
logging -> loguru stage 4
这个提交包含在:
@@ -30,7 +30,7 @@ def gen_image(llm_kwargs, prompt, resolution="1024x1024", model="dall-e-2", qual
|
|||||||
if style is not None:
|
if style is not None:
|
||||||
data['style'] = style
|
data['style'] = style
|
||||||
response = requests.post(url, headers=headers, json=data, proxies=proxies)
|
response = requests.post(url, headers=headers, json=data, proxies=proxies)
|
||||||
print(response.content)
|
# logger.info(response.content)
|
||||||
try:
|
try:
|
||||||
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
|
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
|
||||||
except:
|
except:
|
||||||
@@ -76,7 +76,7 @@ def edit_image(llm_kwargs, prompt, image_path, resolution="1024x1024", model="da
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(url, headers=headers, files=files, proxies=proxies)
|
response = requests.post(url, headers=headers, files=files, proxies=proxies)
|
||||||
print(response.content)
|
# logger.info(response.content)
|
||||||
try:
|
try:
|
||||||
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
|
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
|
||||||
except:
|
except:
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
from toolbox import update_ui, trimmed_format_exc, get_conf, get_log_folder, promote_file_to_downloadzone, check_repeat_upload, map_file_to_sha256
|
from toolbox import update_ui, trimmed_format_exc, get_conf, get_log_folder, promote_file_to_downloadzone, check_repeat_upload, map_file_to_sha256
|
||||||
from toolbox import CatchException, report_exception, update_ui_lastest_msg, zip_result, gen_time_str
|
from toolbox import CatchException, report_exception, update_ui_lastest_msg, zip_result, gen_time_str
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
import glob, os, requests, time, json, tarfile
|
import glob, os, requests, time, json, tarfile
|
||||||
|
|
||||||
pj = os.path.join
|
pj = os.path.join
|
||||||
@@ -178,7 +180,7 @@ def pdf2tex_project(pdf_file_path, plugin_kwargs):
|
|||||||
|
|
||||||
if response.ok:
|
if response.ok:
|
||||||
pdf_id = response.json()["pdf_id"]
|
pdf_id = response.json()["pdf_id"]
|
||||||
print(f"PDF processing initiated. PDF ID: {pdf_id}")
|
logger.info(f"PDF processing initiated. PDF ID: {pdf_id}")
|
||||||
|
|
||||||
# Step 2: Check processing status
|
# Step 2: Check processing status
|
||||||
while True:
|
while True:
|
||||||
@@ -186,12 +188,12 @@ def pdf2tex_project(pdf_file_path, plugin_kwargs):
|
|||||||
conversion_data = conversion_response.json()
|
conversion_data = conversion_response.json()
|
||||||
|
|
||||||
if conversion_data["status"] == "completed":
|
if conversion_data["status"] == "completed":
|
||||||
print("PDF processing completed.")
|
logger.info("PDF processing completed.")
|
||||||
break
|
break
|
||||||
elif conversion_data["status"] == "error":
|
elif conversion_data["status"] == "error":
|
||||||
print("Error occurred during processing.")
|
logger.info("Error occurred during processing.")
|
||||||
else:
|
else:
|
||||||
print(f"Processing status: {conversion_data['status']}")
|
logger.info(f"Processing status: {conversion_data['status']}")
|
||||||
time.sleep(5) # wait for a few seconds before checking again
|
time.sleep(5) # wait for a few seconds before checking again
|
||||||
|
|
||||||
# Step 3: Save results to local files
|
# Step 3: Save results to local files
|
||||||
@@ -206,7 +208,7 @@ def pdf2tex_project(pdf_file_path, plugin_kwargs):
|
|||||||
output_path = os.path.join(output_dir, output_name)
|
output_path = os.path.join(output_dir, output_name)
|
||||||
with open(output_path, "wb") as output_file:
|
with open(output_path, "wb") as output_file:
|
||||||
output_file.write(response.content)
|
output_file.write(response.content)
|
||||||
print(f"tex.zip file saved at: {output_path}")
|
logger.info(f"tex.zip file saved at: {output_path}")
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
unzip_dir = os.path.join(output_dir, file_name_wo_dot)
|
unzip_dir = os.path.join(output_dir, file_name_wo_dot)
|
||||||
@@ -216,7 +218,7 @@ def pdf2tex_project(pdf_file_path, plugin_kwargs):
|
|||||||
return unzip_dir
|
return unzip_dir
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f"Error sending PDF for processing. Status code: {response.status_code}")
|
logger.error(f"Error sending PDF for processing. Status code: {response.status_code}")
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
from crazy_functions.pdf_fns.parse_pdf_via_doc2x import 解析PDF_DOC2X_转Latex
|
from crazy_functions.pdf_fns.parse_pdf_via_doc2x import 解析PDF_DOC2X_转Latex
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from toolbox import update_ui, trimmed_format_exc, promote_file_to_downloadzone, get_log_folder
|
from toolbox import update_ui, trimmed_format_exc, promote_file_to_downloadzone, get_log_folder
|
||||||
from toolbox import CatchException, report_exception, write_history_to_file, zip_folder
|
from toolbox import CatchException, report_exception, write_history_to_file, zip_folder
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
class PaperFileGroup():
|
class PaperFileGroup():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -33,7 +33,7 @@ class PaperFileGroup():
|
|||||||
self.sp_file_index.append(index)
|
self.sp_file_index.append(index)
|
||||||
self.sp_file_tag.append(self.file_paths[index] + f".part-{j}.tex")
|
self.sp_file_tag.append(self.file_paths[index] + f".part-{j}.tex")
|
||||||
|
|
||||||
print('Segmentation: done')
|
logger.info('Segmentation: done')
|
||||||
def merge_result(self):
|
def merge_result(self):
|
||||||
self.file_result = ["" for _ in range(len(self.file_paths))]
|
self.file_result = ["" for _ in range(len(self.file_paths))]
|
||||||
for r, k in zip(self.sp_file_result, self.sp_file_index):
|
for r, k in zip(self.sp_file_result, self.sp_file_index):
|
||||||
@@ -122,7 +122,7 @@ def 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, ch
|
|||||||
pfg.write_result()
|
pfg.write_result()
|
||||||
pfg.zip_result()
|
pfg.zip_result()
|
||||||
except:
|
except:
|
||||||
print(trimmed_format_exc())
|
logger.error(trimmed_format_exc())
|
||||||
|
|
||||||
# <-------- 整理结果,退出 ---------->
|
# <-------- 整理结果,退出 ---------->
|
||||||
create_report_file_name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + f"-chatgpt.polish.md"
|
create_report_file_name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + f"-chatgpt.polish.md"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from toolbox import update_ui, promote_file_to_downloadzone
|
from toolbox import update_ui, promote_file_to_downloadzone
|
||||||
from toolbox import CatchException, report_exception, write_history_to_file
|
from toolbox import CatchException, report_exception, write_history_to_file
|
||||||
fast_debug = False
|
from loguru import logger
|
||||||
|
|
||||||
class PaperFileGroup():
|
class PaperFileGroup():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -33,7 +33,7 @@ class PaperFileGroup():
|
|||||||
self.sp_file_index.append(index)
|
self.sp_file_index.append(index)
|
||||||
self.sp_file_tag.append(self.file_paths[index] + f".part-{j}.tex")
|
self.sp_file_tag.append(self.file_paths[index] + f".part-{j}.tex")
|
||||||
|
|
||||||
print('Segmentation: done')
|
logger.info('Segmentation: done')
|
||||||
|
|
||||||
def 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en'):
|
def 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en'):
|
||||||
import time, os, re
|
import time, os, re
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ def 注释源代码(file_manifest, project_folder, llm_kwargs, plugin_kwargs, ch
|
|||||||
file_tree_struct.manifest[fp].compare_html = compare_html_path
|
file_tree_struct.manifest[fp].compare_html = compare_html_path
|
||||||
with open(compare_html_path, 'w', encoding='utf-8') as f:
|
with open(compare_html_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(html_template)
|
f.write(html_template)
|
||||||
print('done 1')
|
# print('done 1')
|
||||||
|
|
||||||
chatbot.append([None, f"正在处理:"])
|
chatbot.append([None, f"正在处理:"])
|
||||||
futures = []
|
futures = []
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户