JohnKouf's picture
Update app.py
04627a4 verified
raw
history blame
2.26 kB
# 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()