|
45 | 45 | all_reports[instance] = report_df |
46 | 46 |
|
47 | 47 | # Generate individual model size report (Markdown) |
48 | | - report_df.columns = ["Number"] # Change column name for individual report |
49 | | - report_df.to_markdown("gdplib/" + instance + "/" + "model_size_report.md") |
| 48 | + individual_report_df = report_df.copy() |
| 49 | + individual_report_df.columns = ["Number"] # Change column name for individual report |
| 50 | + individual_report_df.to_markdown("gdplib/" + instance + "/" + "model_size_report.md") |
50 | 51 | except Exception as e: |
51 | 52 | print(f"Error processing {instance}: {str(e)}") |
52 | 53 | continue |
|
61 | 62 | combined_df = combined_df.sort_index(axis=1) |
62 | 63 |
|
63 | 64 | # Generate the combined report |
64 | | - combined_report = "## Model Size Comparison\n\n" |
65 | | - combined_report += "The following table shows the size metrics for all models in GDPlib:\n\n" |
66 | | - combined_report += combined_df.to_markdown() |
67 | | - combined_report += "\n\nThis table was automatically generated using the `generate_model_size_report.py` script.\n" |
| 65 | + combined_report = "## Model Size Comparison\n\n" |
| 66 | + combined_report += "The following table shows the size metrics for all models in GDPlib:\n\n" |
| 67 | + combined_report += combined_df.to_markdown() |
| 68 | + combined_report += "\n\nThis table was automatically generated using the `generate_model_size_report.py` script.\n" |
68 | 69 |
|
69 | | - # Read current README content |
70 | | - with open("README.md", "r") as f: |
71 | | - readme_content = f.read() |
| 70 | + # Read current README content |
| 71 | + with open("README.md", "r") as f: |
| 72 | + readme_content = f.read() |
72 | 73 |
|
73 | | - # Find the position to insert the table (after "## Model Size Example") |
74 | | - size_example_pos = readme_content.find("## Model Size Example") |
75 | | - if size_example_pos == -1: |
76 | | - raise ValueError("The section '## Model Size Example' was not found in README.md.") |
77 | | - |
78 | | - if size_example_pos == -1: |
79 | | - print("Warning: '## Model Size Example' section not found in README.md. Appending report to the end of the file.") |
80 | | - new_readme = readme_content + "\n\n" + combined_report |
81 | | - else: |
82 | | - next_section_pos = readme_content.find("##", size_example_pos + 1) |
83 | | - # Create new README content |
84 | | - new_readme = ( |
85 | | - readme_content[:size_example_pos] + |
86 | | - combined_report + |
87 | | - "\n\n" + |
88 | | - readme_content[next_section_pos:] |
89 | | - ) |
90 | | - # Write updated README |
91 | | - with open("README.md", "w") as f: |
92 | | - f.write(new_readme) |
| 74 | + # Find the position to insert the table (after "## Model Size Example") |
| 75 | + size_example_pos = readme_content.find("## Model Size Example") |
| 76 | + |
| 77 | + if size_example_pos == -1: |
| 78 | + print("Warning: '## Model Size Example' section not found in README.md. Appending report to the end of the file.") |
| 79 | + new_readme = readme_content + "\n\n" + combined_report |
| 80 | + else: |
| 81 | + next_section_pos = readme_content.find("##", size_example_pos + 1) |
| 82 | + # Create new README content |
| 83 | + new_readme = ( |
| 84 | + readme_content[:size_example_pos] + |
| 85 | + combined_report + |
| 86 | + "\n\n" + |
| 87 | + readme_content[next_section_pos:] |
| 88 | + ) |
| 89 | + |
| 90 | + # Write updated README |
| 91 | + with open("README.md", "w") as f: |
| 92 | + f.write(new_readme) |
0 commit comments