|
from transformers import BartForConditionalGeneration, BartTokenizer |
|
|
|
|
|
import gradio as gr |
|
|
|
|
|
model_name = "facebook/bart-large-cnn" |
|
tokenizer = BartTokenizer.from_pretrained(model_name) |
|
model = BartForConditionalGeneration.from_pretrained(model_name) |
|
|
|
|
|
def generate_text(prompt): |
|
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512) |
|
summary_ids = model.generate(inputs["input_ids"], 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="text", outputs="text",title="TeLLMyStory",description="Enter your story idea and the model will generate the story based on it.") |
|
|
|
|
|
|
|
interface.launch(share=True) |
|
|