textsummary / app.py
rexthecoder's picture
Update app.py
ffa05ed
raw
history blame
774 Bytes
import gradio as gr
from pydantic import BaseModel
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("mrm8488/flan-t5-small-finetuned-samsum")
model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/flan-t5-small-finetuned-samsum")
class Input(BaseModel):
text: str
def predict_sentiment(input: Input, words):
input_ids = tokenizer(input.text, return_tensors="pt").input_ids
outputs = model.generate(input_ids, max_length=words)
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
return f"{decoded_output}"
iface = gr.Interface(fn=predict_sentiment, inputs=[gr.Textbox(lines=2, placeholder="Conversations Here..."), gr.Slider(10, 100)], outputs="text")
iface.launch()