Spaces:
Runtime error
Runtime error
✨ save parameters
Browse filesSigned-off-by: peter szemraj <[email protected]>
app.py
CHANGED
@@ -182,7 +182,8 @@ def proc_submission(
|
|
182 |
html += ""
|
183 |
|
184 |
# save to file
|
185 |
-
|
|
|
186 |
|
187 |
return html, sum_text_out, scores_out, saved_file
|
188 |
|
|
|
182 |
html += ""
|
183 |
|
184 |
# save to file
|
185 |
+
settings["model_name"] = model_name
|
186 |
+
saved_file = saves_summary(_summaries, **settings)
|
187 |
|
188 |
return html, sum_text_out, scores_out, saved_file
|
189 |
|
utils.py
CHANGED
@@ -88,19 +88,17 @@ def load_example_filenames(example_path: str or Path):
|
|
88 |
return examples
|
89 |
|
90 |
|
91 |
-
def saves_summary(
|
|
|
|
|
92 |
"""
|
93 |
-
|
94 |
saves_summary - save the summary generated from summarize_via_tokenbatches() to a text file
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
**settings,
|
101 |
-
)
|
102 |
"""
|
103 |
-
|
104 |
outpath = (
|
105 |
Path.cwd() / f"document_summary_{get_timestamp()}.txt"
|
106 |
if outpath is None
|
@@ -114,19 +112,26 @@ def saves_summary(summarize_output, outpath: str or Path = None, add_signature=T
|
|
114 |
with open(
|
115 |
outpath,
|
116 |
"w",
|
|
|
117 |
) as fo:
|
118 |
-
if add_signature:
|
119 |
-
fo.write(
|
120 |
-
"Generated with the Document Summarization space :) https://hf.co/spaces/pszemraj/document-summarization\n\n"
|
121 |
-
)
|
122 |
fo.writelines(full_summary)
|
|
|
|
|
|
|
|
|
|
|
123 |
with open(
|
124 |
outpath,
|
125 |
"a",
|
126 |
) as fo:
|
127 |
fo.write("\n" * 3)
|
128 |
-
fo.write(f"
|
129 |
fo.writelines(scores_text)
|
130 |
-
fo.write("\n\n
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
132 |
return outpath
|
|
|
88 |
return examples
|
89 |
|
90 |
|
91 |
+
def saves_summary(
|
92 |
+
summarize_output, outpath: str or Path = None, add_signature=True, **kwargs
|
93 |
+
):
|
94 |
"""
|
|
|
95 |
saves_summary - save the summary generated from summarize_via_tokenbatches() to a text file
|
96 |
|
97 |
+
summarize_output: output from summarize_via_tokenbatches()
|
98 |
+
outpath: path to the output file
|
99 |
+
add_signature: whether to add a signature to the output file
|
100 |
+
kwargs: additional keyword arguments to include in the output file
|
|
|
|
|
101 |
"""
|
|
|
102 |
outpath = (
|
103 |
Path.cwd() / f"document_summary_{get_timestamp()}.txt"
|
104 |
if outpath is None
|
|
|
112 |
with open(
|
113 |
outpath,
|
114 |
"w",
|
115 |
+
encoding="utf-8",
|
116 |
) as fo:
|
|
|
|
|
|
|
|
|
117 |
fo.writelines(full_summary)
|
118 |
+
fo.write("\n\n")
|
119 |
+
if add_signature:
|
120 |
+
fo.write("\n\n---\n\n")
|
121 |
+
fo.write("Generated with the Document Summarization space :)\n\n")
|
122 |
+
fo.write("https://hf.co/spaces/pszemraj/document-summarization\n\n")
|
123 |
with open(
|
124 |
outpath,
|
125 |
"a",
|
126 |
) as fo:
|
127 |
fo.write("\n" * 3)
|
128 |
+
fo.write(f"## Section Scores:\n\n")
|
129 |
fo.writelines(scores_text)
|
130 |
+
fo.write("\n\n")
|
131 |
+
fo.write(f"Date: {get_timestamp()}\n\n")
|
132 |
+
if kwargs:
|
133 |
+
fo.write("---\n\n")
|
134 |
+
fo.write("Parameters:\n\n")
|
135 |
+
for key, value in kwargs.items():
|
136 |
+
fo.write(f"{key}: {value}\n")
|
137 |
return outpath
|