File size: 978 Bytes
f564393
8fac661
f564393
459d416
8fac661
 
f564393
8fac661
 
 
 
f564393
8fac661
459d416
f564393
8fac661
 
f564393
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
from transformers import BartTokenizer, BartForConditionalGeneration

model_name = "facebook/bart-large-cnn"  # Example BART model for demonstration
tokenizer = BartTokenizer.from_pretrained(model_name)
model = BartForConditionalGeneration.from_pretrained(model_name)

def generate_text(prompt):
    inputs = tokenizer.encode("summarize: " + prompt, return_tensors="pt", max_length=1024, truncation=True)
    summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
    return tokenizer.decode(summary_ids[0], skip_special_tokens=True)

interface = gr.Interface(fn=generate_text,
                         inputs=gr.Textbox(lines=5, placeholder="Enter Text Here..."),
                         outputs="text",
                         title="Text Generation with BART",
                         description="Enter text to generate a summary.")

if __name__ == "__main__":
    interface.launch()