Spaces:
Running
Running
shaocongma
commited on
Commit
•
018eb6d
1
Parent(s):
990b1e1
Print Error Message to User.
Browse files- app.py +20 -11
- utils/tex_processing.py +2 -6
app.py
CHANGED
@@ -63,7 +63,10 @@ def wrapped_generator(paper_title, paper_description, openai_api_key=None,
|
|
63 |
bib_refs = bib_refs.name
|
64 |
if openai_api_key is not None:
|
65 |
openai.api_key = openai_api_key
|
66 |
-
|
|
|
|
|
|
|
67 |
|
68 |
if cache_mode:
|
69 |
from utils.storage import list_all_files, download_file, upload_file
|
@@ -78,17 +81,23 @@ def wrapped_generator(paper_title, paper_description, openai_api_key=None,
|
|
78 |
download_file(file_name)
|
79 |
return file_name
|
80 |
else:
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
# output = fake_generate_backgrounds(title, description, openai_key)
|
83 |
output = generate_draft(paper_title, paper_description, template=paper_template,
|
84 |
tldr=tldr, sections=selected_sections, bib_refs=bib_refs, model=model)
|
85 |
-
|
86 |
-
|
87 |
-
return output
|
88 |
-
else:
|
89 |
-
# output = fake_generate_backgrounds(title, description, openai_key)
|
90 |
-
output = generate_draft(paper_title, paper_description, template=paper_template,
|
91 |
-
tldr=tldr, sections=selected_sections, bib_refs=bib_refs, model=model)
|
92 |
return output
|
93 |
|
94 |
|
@@ -150,7 +159,7 @@ with gr.Blocks(theme=theme) as demo:
|
|
150 |
|
151 |
***2023-06-08 Update***:
|
152 |
* 目前对英文的生成效果更好. 如果需要中文文章可以使用[GPT学术优化](https://github.com/binary-husky/gpt_academic)的`Latex全文翻译、润色`功能.
|
153 |
-
*
|
154 |
|
155 |
***2023-05-17 Update***: 我的API的余额用完了, 所以这个月不再能提供GPT-4的API Key. 这里为大家提供了一个位置输入OpenAI API Key. 同时也提供了GPT-3.5的兼容. 欢迎大家自行体验.
|
156 |
|
@@ -266,4 +275,4 @@ with gr.Blocks(theme=theme) as demo:
|
|
266 |
inputs=[title_refs, slider_refs, key], outputs=json_output)
|
267 |
|
268 |
demo.queue(concurrency_count=1, max_size=5, api_open=False)
|
269 |
-
demo.launch()
|
|
|
63 |
bib_refs = bib_refs.name
|
64 |
if openai_api_key is not None:
|
65 |
openai.api_key = openai_api_key
|
66 |
+
try:
|
67 |
+
openai.Model.list()
|
68 |
+
except Exception as e:
|
69 |
+
raise gr.Error(f"Key错误. Error: {e}")
|
70 |
|
71 |
if cache_mode:
|
72 |
from utils.storage import list_all_files, download_file, upload_file
|
|
|
81 |
download_file(file_name)
|
82 |
return file_name
|
83 |
else:
|
84 |
+
try:
|
85 |
+
# generate the result.
|
86 |
+
# output = fake_generate_backgrounds(title, description, openai_key)
|
87 |
+
output = generate_draft(paper_title, paper_description, template=paper_template,
|
88 |
+
tldr=tldr, sections=selected_sections, bib_refs=bib_refs, model=model)
|
89 |
+
# output = generate_draft(paper_title, paper_description, template, "gpt-4")
|
90 |
+
upload_file(output)
|
91 |
+
return output
|
92 |
+
except Exception as e:
|
93 |
+
raise gr.Error(f"生成失败. Error {e.__name__}: {e}")
|
94 |
+
else:
|
95 |
+
try:
|
96 |
# output = fake_generate_backgrounds(title, description, openai_key)
|
97 |
output = generate_draft(paper_title, paper_description, template=paper_template,
|
98 |
tldr=tldr, sections=selected_sections, bib_refs=bib_refs, model=model)
|
99 |
+
except Exception as e:
|
100 |
+
raise gr.Error(f"生成失败. Error: {e}")
|
|
|
|
|
|
|
|
|
|
|
101 |
return output
|
102 |
|
103 |
|
|
|
159 |
|
160 |
***2023-06-08 Update***:
|
161 |
* 目前对英文的生成效果更好. 如果需要中文文章可以使用[GPT学术优化](https://github.com/binary-husky/gpt_academic)的`Latex全文翻译、润色`功能.
|
162 |
+
* GPT3.5模型可能会因为Token数不够导致一部分章节为空. 可以在高级设置里减少生成的章节.
|
163 |
|
164 |
***2023-05-17 Update***: 我的API的余额用完了, 所以这个月不再能提供GPT-4的API Key. 这里为大家提供了一个位置输入OpenAI API Key. 同时也提供了GPT-3.5的兼容. 欢迎大家自行体验.
|
165 |
|
|
|
275 |
inputs=[title_refs, slider_refs, key], outputs=json_output)
|
276 |
|
277 |
demo.queue(concurrency_count=1, max_size=5, api_open=False)
|
278 |
+
demo.launch(show_error=True)
|
utils/tex_processing.py
CHANGED
@@ -57,16 +57,12 @@ def create_copies(output_dir):
|
|
57 |
shutil.copy2(original_fig, target_fig)
|
58 |
|
59 |
|
60 |
-
|
61 |
|
62 |
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
-
|
66 |
-
directory_path = "outputs/outputs_20230520_110413/"
|
67 |
-
path = os.path.join(auto_draft, directory_path)
|
68 |
-
|
69 |
-
create_copies(path)
|
70 |
|
71 |
|
72 |
|
|
|
57 |
shutil.copy2(original_fig, target_fig)
|
58 |
|
59 |
|
60 |
+
# todo: post-processing the generated algorithm for correct compile.
|
61 |
|
62 |
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
+
pass
|
|
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
|