File size: 965 Bytes
945bbd0
3250e90
72fde3b
 
3250e90
 
 
72fde3b
 
3250e90
 
 
 
 
 
 
 
72fde3b
 
3250e90
 
 
72fde3b
 
945bbd0
3250e90
 
 
 
945bbd0
 
3250e90
1b33daa
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
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline

# Load the model and tokenizer
model_name = 'IMISLab/GreekWiki-umt5-base'
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=220,
    truncation=True
)

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

# Create Gradio interface
iface = gr.Interface(
    fn=generate_summary,  # The function that Gradio will use
    inputs=gr.Textbox(label="Input Text", lines=5, placeholder="Enter the text to summarize..."),
    outputs=gr.Textbox(label="Summary"),
    live=True
)

# Launch the Gradio interface
iface.launch()