-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
25 lines (21 loc) · 923 Bytes
/
app.py
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
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
# Load the trained model from Hugging Face
model_name = "./"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Define the summarization function
def summarize(text):
inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
summary_ids = model.generate(inputs["input_ids"], max_length=150, min_length=40, length_penalty=2.0, num_beams=4)
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
# Create Gradio UI
iface = gr.Interface(
fn=summarize,
inputs=gr.Textbox(lines=5, placeholder="Enter text to summarize..."),
outputs=gr.Textbox(label="Summarized Text"),
title="Text Summarization with BART",
description="Enter an article and get a summarized version instantly.",
)
# Launch the app
iface.launch()