File size: 669 Bytes
5ed2f66 341b746 c3db1be 341b746 c3db1be 923802c c3db1be 923802c c3db1be |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import torch
import gradio as gr
from transformers import T5Tokenizer, T5ForConditionalGeneration
def generate_text(input_text):
# Load pre-trained model and tokenizer
model_name = 'kurry/t5_small_finetuned'
model = T5ForConditionalGeneration.from_pretrained(model_name).to('cpu')
tokenizer = T5Tokenizer.from_pretrained(model_name)
# Generate summary
inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", truncation=True).to('cpu')
outputs = model.generate(inputs)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
iface = gr.Interface(fn=generate_text, inputs='text', outputs='text')
iface.launch()
|