File size: 873 Bytes
7b6f763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from transformers import pipeline
from transformers import AutoModelForSeq2SeqLM
from transformers import AutoTokenizer


# Load trained model
model = AutoModelForSeq2SeqLM.from_pretrained("/output/reframer")
tokenizer = AutoTokenizer.from_pretrained("/output/reframer")
reframer = pipeline('summarization', model=model, tokenizer=tokenizer)


def reframe(text, strategy):
    text_with_strategy = text +  "Strategy: ['" + strategy + "']"
    return reframer(text_with_strategy)[0]['summary_text']


import gradio as gr
with gr.Blocks() as demo:
    text = gr.Textbox(label="Original Text")
    radio = gr.Radio(
        ["thankfulness", "neutralizing", "optimism", "growth", "impermanence", "self_affirmation"], label="Strategy to use?"
    )
    output = gr.Textbox(label="Reframed Output")
    radio.change(fn=reframe, inputs=[text, radio], outputs=output)
demo.launch()