astro21 commited on
Commit
30e894a
·
1 Parent(s): acecd49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -18,24 +18,28 @@ def summarize_text(input_text):
18
  summarized_chunks = []
19
  for chunk in chunks:
20
  chunk_counter += 1
21
- print(f"Chunk {chunk_counter}:") # Print the chunk number
22
  # Summarize each chunk
23
  summarized_chunk = summarizer(chunk, max_length=128, min_length=64, do_sample=False)[0]['summary_text']
24
- summarized_chunks.append(summarized_chunk)
25
 
26
  # Concatenate the summaries
27
  summarized_text = "\n".join(summarized_chunks)
28
  return summarized_text
29
 
30
- def summarize_text_files(files):
31
- if files is not None:
32
- content = ""
33
- for file in files:
34
- content += file.read().decode("utf-8")
 
 
 
 
 
35
  return summarize_text(content)
36
 
37
- input_type = gr.inputs.File("text", type="text", label="Upload Text Files", multiple=True)
38
 
39
- demo = gr.Interface(fn=summarize_text_files, inputs=input_type, outputs="text", live=True)
40
 
41
  demo.launch()
 
18
  summarized_chunks = []
19
  for chunk in chunks:
20
  chunk_counter += 1
 
21
  # Summarize each chunk
22
  summarized_chunk = summarizer(chunk, max_length=128, min_length=64, do_sample=False)[0]['summary_text']
23
+ summarized_chunks.append(f"Chunk {chunk_counter}:\n{summarized_chunk}")
24
 
25
  # Concatenate the summaries
26
  summarized_text = "\n".join(summarized_chunks)
27
  return summarized_text
28
 
29
+ python
30
+ def read_file(file_path):
31
+ with open(file_path, 'r') as file:
32
+ content = file.read()
33
+ return content
34
+
35
+
36
+ def summarize_text_file(file):
37
+ if file is not None:
38
+ content = read_file(file.name)
39
  return summarize_text(content)
40
 
41
+ input_type = gr.inputs.File("text")
42
 
43
+ demo = gr.Interface(fn=summarize_text_file, inputs=input_type, outputs="text", live=True)
44
 
45
  demo.launch()