File size: 2,255 Bytes
04627a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
945bbd0
04627a4
155660f
04627a4
 
155660f
04627a4
 
 
 
 
 
945bbd0
04627a4
 
da39e44
04627a4
 
 
945bbd0
 
da39e44
1b33daa
04627a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# import gradio as gr
# from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline

# # Load the model and tokenizer
# model_name = 'IMISLab/GreekT5-umt5-base-greeksum'
# model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
# tokenizer = AutoTokenizer.from_pretrained(model_name)

# # Set up the summarizer pipeline
# summarizer = pipeline(
#     'summarization',
#     model=model,
#     tokenizer=tokenizer,
#     device=-1,  # -1 for CPU; set to 0 for GPU if available
#     max_new_tokens=128,
#     truncation=True
# )

# # Define the summarization function
# def summarize_text(text):
#     output = summarizer('summarize: ' + text)
#     return output[0]['summary_text']

# # Create a Gradio interface
# iface = gr.Interface(
#     fn=summarize_text,            # Function to run
#     inputs=gr.Textbox(label="Enter Greek Text", placeholder="Type or paste your text here..."),  # Input component
#     outputs=gr.Textbox(label="Summary", interactive=True),  # Output component
#     title="Greek Text Summarization",  # Title for the UI
#     description="This app uses a pre-trained Greek summarization model to generate a brief summary of your input text.",  # Description
#     allow_flagging="never"         # Optional: Disable flagging feature
# )

# # Launch the interface
# iface.launch()

import gradio as gr
from transformers import pipeline

# Load the summarizer model
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

# Function to summarize text
def summarize_text(article):
    summary = summarizer(article, max_length=130, min_length=30, do_sample=False)
    return summary[0]['summary_text']

# Create the Gradio interface
iface = gr.Interface(
    fn=summarize_text,  # The function to be called
    inputs=gr.Textbox(label="Enter Article Text", placeholder="Type or paste the article here..."),  # Input component
    outputs=gr.Textbox(label="Summary", interactive=True),  # Output component
    title="Text Summarization",  # Title of the interface
    description="This app uses a pre-trained summarization model (BART) to summarize the provided article.",  # Description
    allow_flagging="never"  # Disable flagging
)

# Launch the interface
iface.launch()