File size: 832 Bytes
07418f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer

# Load model and tokenizer
model_name = "t5-base"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Define pipeline for text summarization
summarizer = pipeline('text2text-generation', model=model, tokenizer=tokenizer)

# Define Gradio interface
def summarize_text(text):
    result = summarizer(text, max_length=100, min_length=30, do_sample=False)[0]
    summary = result['generated_text'].strip()
    return summary

iface = gr.Interface(fn=summarize_text, inputs="text", outputs="text", 
                     title="Text Summarization with Hugging Face and Gradio", 
                     description="Enter text to summarize.")

# Launch Gradio interface
iface.launch()