JohnKouf's picture
Update app.py
9ce0e46 verified
raw
history blame contribute delete
941 Bytes
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
# Load the model and tokenizer
model_name = 'IMISLab/GreekT5-umt5-small-greeksum'
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Set up the summarizer pipeline
summarizer = pipeline(
'summarization',
device = 'cpu',
model = model,
tokenizer = tokenizer,
max_new_tokens = 128,
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()