File size: 1,240 Bytes
d6c533e
 
 
 
7635e33
 
 
 
 
d6c533e
 
7635e33
 
 
 
 
 
 
d6c533e
7635e33
 
 
 
 
 
 
d6c533e
 
 
 
7635e33
 
 
 
 
d6c533e
7635e33
d6c533e
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import torch
import gradio as gr
from transformers import pipeline

# Initialize the summarization pipeline (without float16 for CPU)
pipe = pipeline("summarization", model="Falconsai/text_summarization")

# Store the history
history = []

# Define the summarize function
def summarize(input, clear_history=False):
    # Clear history if the flag is set
    if clear_history:
        history.clear()
        return "History cleared!"

    # Get the summary
    output = pipe(input)
    summary = output[0]['summary_text']
    
    # Store the summary in history
    history.append(summary)
    
    # Return the summary along with the history
    return summary, history

# Define the Gradio interface
iface = gr.Interface(
    fn=summarize,
    inputs=[
        gr.Textbox(lines=10, placeholder="Enter text to summarize here..."),
        gr.Checkbox(label="Clear history", value=False)  # Checkbox to clear history
    ],
    outputs=["text", "json"],  # Show summary and history in json format
    title="Text Summarizer",
    description="Enter a long piece of text, and the summarizer will provide a concise summary. You can also clear the history of summaries."
)

# Launch the interface
if __name__ == "__main__":
    iface.launch()