SyedMohammedSathiq commited on
Commit
7635e33
·
verified ·
1 Parent(s): 0cd7d25
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -1,23 +1,40 @@
1
  import torch
2
  import gradio as gr
3
- # Use a pipeline as a high-level helper
4
  from transformers import pipeline
5
 
6
- # Initialize the summarization pipeline
7
- pipe = pipeline("summarization", model="Falconsai/text_summarization", torch_dtype=torch.float16)
 
 
 
8
 
9
  # Define the summarize function
10
- def summarize(input):
 
 
 
 
 
 
11
  output = pipe(input)
12
- return output[0]['summary_text']
 
 
 
 
 
 
13
 
14
  # Define the Gradio interface
15
  iface = gr.Interface(
16
  fn=summarize,
17
- inputs=gr.Textbox(lines=10, placeholder="Enter text to summarize here..."),
18
- outputs="text",
 
 
 
19
  title="Text Summarizer",
20
- description="Enter a long piece of text, and the summarizer will provide a concise summary."
21
  )
22
 
23
  # Launch the interface
 
1
  import torch
2
  import gradio as gr
 
3
  from transformers import pipeline
4
 
5
+ # Initialize the summarization pipeline (without float16 for CPU)
6
+ pipe = pipeline("summarization", model="Falconsai/text_summarization")
7
+
8
+ # Store the history
9
+ history = []
10
 
11
  # Define the summarize function
12
+ def summarize(input, clear_history=False):
13
+ # Clear history if the flag is set
14
+ if clear_history:
15
+ history.clear()
16
+ return "History cleared!"
17
+
18
+ # Get the summary
19
  output = pipe(input)
20
+ summary = output[0]['summary_text']
21
+
22
+ # Store the summary in history
23
+ history.append(summary)
24
+
25
+ # Return the summary along with the history
26
+ return summary, history
27
 
28
  # Define the Gradio interface
29
  iface = gr.Interface(
30
  fn=summarize,
31
+ inputs=[
32
+ gr.Textbox(lines=10, placeholder="Enter text to summarize here..."),
33
+ gr.Checkbox(label="Clear history", value=False) # Checkbox to clear history
34
+ ],
35
+ outputs=["text", "json"], # Show summary and history in json format
36
  title="Text Summarizer",
37
+ description="Enter a long piece of text, and the summarizer will provide a concise summary. You can also clear the history of summaries."
38
  )
39
 
40
  # Launch the interface