Spaces:
Runtime error
Runtime error
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() | |