611 else initialize_abstractive_model("facebook/bart-large-xsum")
612 )
613
614 for idx, cluster in tqdm( 615 enumerate(sentence_clusters),
616 desc="Summarizing Clusters",
617 total=len(sentence_clusters),
459
460
461def metadata_to_list(candidate_transcript):
462 json = metadata_to_json(candidate_transcript)463 return json["tokens"]
464
465
177 word = image[y : y + h, x : x + w]
178 return stroke_width(word)
179
180 prev_line_num = 0181
182 def add_line_info(row):
183 """
197 # 0: normal text
198 # 1: subtitle/bold
199 # 2: title text
200 stroke_width = row["stroke_width"]201 height = row["height"]
202 if stroke_width > avg_stroke_width * (1 + gamma) or height > avg_height * (
203 1 + beta
167 ring_buffer.clear()
168
169
170def main(ARGS):171 # Load DeepSpeech model
172 if os.path.isdir(ARGS.model):
173 model_dir = ARGS.model
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()