shaocongma commited on
Commit
3b4e6ce
1 Parent(s): 6387164
auto_backgrounds.py CHANGED
@@ -2,6 +2,7 @@ import os.path
2
  import json
3
  from utils.references import References
4
  from utils.file_operations import hash_name, make_archive, copy_templates
 
5
  from section_generator import section_generation_bg, keywords_generation, figures_generation, section_generation
6
  import logging
7
  import time
@@ -128,7 +129,8 @@ def generate_draft(title, description="", template="ICLR2022",
128
  logging.info(message)
129
  attempts_count += 1
130
  time.sleep(20)
131
-
 
132
  input_dict = {"title": title, "description": description, "generator": "generate_draft"}
133
  filename = hash_name(input_dict) + ".zip"
134
  print("\nMission completed.\n")
 
2
  import json
3
  from utils.references import References
4
  from utils.file_operations import hash_name, make_archive, copy_templates
5
+ from utils.tex_processing import create_copies
6
  from section_generator import section_generation_bg, keywords_generation, figures_generation, section_generation
7
  import logging
8
  import time
 
129
  logging.info(message)
130
  attempts_count += 1
131
  time.sleep(20)
132
+ # post-processing
133
+ create_copies(destination_folder)
134
  input_dict = {"title": title, "description": description, "generator": "generate_draft"}
135
  filename = hash_name(input_dict) + ".zip"
136
  print("\nMission completed.\n")
utils/prompts.py CHANGED
@@ -116,11 +116,15 @@ def generate_paper_prompts(paper_info, section):
116
  # ref_instruction_subprompt - give AI references
117
  # self_subprompt - give AI existing written parts
118
  # output_subprompt - tell AI how to output
119
- fundamental_subprompt = "Your task is to write the {section} section of the machine learning paper with the title '{title}'. {description}\n"
120
  instruction_subprompt = "\n" \
121
  "Your response should follow the following instructions:\n" \
122
  "{instruction}\n" \
123
  "- Start with \section{{{section}}}\n"
 
 
 
 
124
  ref_instruction_subprompt = "- Read references. " \
125
  "Every time you use information from the references, you need to appropriately cite it (using \citep or \citet)." \
126
  "For example of \citep, the sentence where you use information from lei2022adaptive \citep{{lei2022adaptive}}. " \
@@ -141,7 +145,7 @@ def generate_paper_prompts(paper_info, section):
141
  template=fundamental_subprompt + instruction_subprompt + self_subprompt + output_subprompt)
142
  abstract_prompts = PromptTemplate(
143
  input_variables=["title", "description", "instruction", "section", "paper"],
144
- template=fundamental_subprompt + instruction_subprompt + self_subprompt + abstract_output_subprompt)
145
 
146
  if section in ["introduction", "related works", "backgrounds"]:
147
  # title + references + instruction
 
116
  # ref_instruction_subprompt - give AI references
117
  # self_subprompt - give AI existing written parts
118
  # output_subprompt - tell AI how to output
119
+ fundamental_subprompt = "Your task is to write the {section} section of the paper with the title '{title}'. {description}\n"
120
  instruction_subprompt = "\n" \
121
  "Your response should follow the following instructions:\n" \
122
  "{instruction}\n" \
123
  "- Start with \section{{{section}}}\n"
124
+
125
+ abstract_instruction_subprompt = "\n" \
126
+ "Your response should follow the following instructions:\n" \
127
+ "{instruction}\n"
128
  ref_instruction_subprompt = "- Read references. " \
129
  "Every time you use information from the references, you need to appropriately cite it (using \citep or \citet)." \
130
  "For example of \citep, the sentence where you use information from lei2022adaptive \citep{{lei2022adaptive}}. " \
 
145
  template=fundamental_subprompt + instruction_subprompt + self_subprompt + output_subprompt)
146
  abstract_prompts = PromptTemplate(
147
  input_variables=["title", "description", "instruction", "section", "paper"],
148
+ template=fundamental_subprompt + abstract_instruction_subprompt + self_subprompt + abstract_output_subprompt)
149
 
150
  if section in ["introduction", "related works", "backgrounds"]:
151
  # title + references + instruction
utils/tex_processing.py CHANGED
@@ -1,4 +1,6 @@
1
  import os
 
 
2
 
3
  def replace_title(save_to_path, title):
4
  # Define input and output file names
@@ -25,5 +27,46 @@ def replace_title(save_to_path, title):
25
 
26
  # return all .png and replace it using placeholder.
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
 
 
1
  import os
2
+ import re
3
+ import shutil
4
 
5
  def replace_title(save_to_path, title):
6
  # Define input and output file names
 
27
 
28
  # return all .png and replace it using placeholder.
29
 
30
+ def find_tex_files(directory_path):
31
+ tex_files = []
32
+
33
+ for filename in os.listdir(directory_path):
34
+ if filename.endswith(".tex"):
35
+ tex_files.append(filename)
36
+
37
+ return tex_files
38
+
39
+ def find_figure_names(tex_file_path):
40
+ # Regular expression pattern to find \includegraphics commands
41
+ pattern = r'\\includegraphics.*?{(.*?)}'
42
+ with open(tex_file_path, 'r') as file:
43
+ content = file.read()
44
+ # Find all matches in the file content
45
+ matches = re.findall(pattern, content)
46
+ # Matches will be a list of figure names
47
+ return matches
48
+
49
+ def create_copies(output_dir):
50
+ tex_files = find_tex_files(output_dir)
51
+ for tex_file in tex_files:
52
+ path = os.path.join(output_dir, tex_file)
53
+ all_figs = find_figure_names(path)
54
+ for fig in all_figs:
55
+ original_fig = os.path.join(output_dir, "fig.png")
56
+ target_fig = os.path.join(output_dir, fig)
57
+ shutil.copy2(original_fig, target_fig)
58
+
59
+
60
+
61
+
62
+
63
+
64
+ if __name__ == "__main__":
65
+ auto_draft = os.path.dirname(os.getcwd())
66
+ directory_path = "outputs/outputs_20230520_110413/"
67
+ path = os.path.join(auto_draft, directory_path)
68
+
69
+ create_copies(path)
70
+
71
 
72