grapplerulrich commited on
Commit
164690b
1 Parent(s): 561abab

Add progress bar and seach result numbers

Browse files
Files changed (1) hide show
  1. main.py +33 -24
main.py CHANGED
@@ -62,34 +62,43 @@ def main():
62
  except Exception as exception:
63
  st.exception(exception)
64
  return
65
-
66
 
67
- for result in results:
68
- url_id = uuid.uuid5( uuid.NAMESPACE_URL, result['link'] ).hex
69
- st.write(result['link'])
70
- st.write(url_id)
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  try:
73
- content = get_url_content( result['link'] )
 
74
  except Exception as exception:
75
- st.exception(exception)
76
- continue
77
-
78
- file_path = 'summaries/' + url_id + '.json'
79
- if exists( file_path ):
80
- with open( file_path, 'r' ) as file:
81
- summary = json.load( file )
82
- else:
83
- try:
84
- summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
85
- summary = summarizer(content, max_length=130, min_length=30, do_sample=False, truncation=True)
86
- except Exception as exception:
87
- raise exception
88
- with open( file_path, 'w' ) as file:
89
- json.dump( summary, file )
90
-
91
- for sentence in summary:
92
- st.write(sentence['summary_text'])
93
 
94
  if __name__ == '__main__':
95
  main()
 
62
  except Exception as exception:
63
  st.exception(exception)
64
  return
 
65
 
66
+ number_of_results = len( results )
67
+ st.success( 'Found {} results.'.format( number_of_results ) )
 
 
68
 
69
+ progress_bar = st.progress(0)
70
+
71
+ # for result in results:
72
+ for index, result in enumerate(results):
73
+ url_id = uuid.uuid5( uuid.NAMESPACE_URL, result['link'] ).hex
74
+ st.write(result['link'])
75
+ st.write(url_id)
76
+
77
+ try:
78
+ content = get_url_content( result['link'] )
79
+ except Exception as exception:
80
+ st.exception(exception)
81
+ progress_bar.progress( ( index + 1 ) / number_of_results )
82
+ continue
83
+
84
+ file_path = 'summaries/' + url_id + '.json'
85
+ if exists( file_path ):
86
+ with open( file_path, 'r' ) as file:
87
+ summary = json.load( file )
88
+ else:
89
  try:
90
+ summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
91
+ summary = summarizer(content, max_length=130, min_length=30, do_sample=False, truncation=True)
92
  except Exception as exception:
93
+ raise exception
94
+
95
+ with open( file_path, 'w' ) as file:
96
+ json.dump( summary, file )
97
+
98
+ for sentence in summary:
99
+ st.write(sentence['summary_text'])
100
+
101
+ progress_bar.progress( ( index + 1 ) / number_of_results )
 
 
 
 
 
 
 
 
 
102
 
103
  if __name__ == '__main__':
104
  main()