grapplerulrich commited on
Commit
48cf3e1
1 Parent(s): 6e5749a

Fix issues loading cache & save content in same format as summary

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -88,15 +88,22 @@ def get_summary( url, keywords ):
88
  # Check if content cache file exists.
89
  if exists( content_cache ):
90
  with open( content_cache, 'r' ) as file:
91
- content = file
92
  else:
93
  content = prep_chunks_summary( strings, keywords )
94
  # Save content to cache file.
95
  with open( content_cache, 'w' ) as file:
96
- file.write( content )
97
-
98
- # Generate summary from compiled content.
99
- summary = generate_summary( content, 200 )
 
 
 
 
 
 
 
100
  except Exception as exception:
101
  raise exception
102
  # Save results to cache file.
 
88
  # Check if content cache file exists.
89
  if exists( content_cache ):
90
  with open( content_cache, 'r' ) as file:
91
+ content = file.read().rstrip()
92
  else:
93
  content = prep_chunks_summary( strings, keywords )
94
  # Save content to cache file.
95
  with open( content_cache, 'w' ) as file:
96
+ print(content, file=file)
97
+
98
+ max_lenth = 200
99
+ # Rudementary method to count number of tokens in a chunk.
100
+ word_count = len( content.split(' ') )
101
+ # If content is longer then 200 words summarize it.
102
+ if word_count > max_lenth:
103
+ # Generate summary from compiled content.
104
+ summary = generate_summary( content, max_lenth )
105
+ else:
106
+ summary = [ { "summary_text": content } ]
107
  except Exception as exception:
108
  raise exception
109
  # Save results to cache file.