File size: 2,402 Bytes
2296bb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import gradio as gr
from transformers import T5Tokenizer, T5ForConditionalGeneration

# xl size run out of memory on 16GB vm
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large")

title = ""

def get_examples ():
    return [
    ["Being a Happier and Healthier Person"],
    ["Learn to Use Mindfulness to Affect Well Being"],
    ["Eating and Drinking - Find Healthy Nutrition Habits"],
    ["Drinking - Find Reasons and Cut Back or Quit Entirely"],
    ["Stress is relieved by quieting your mind, getting exercise and time with nature"],
    ["Reprogram Pain Stress Reactions"],
    ["Brain gamification"],
    ["Mental Body Scan"],
    ["Stretch, Calm, Breath"],
    ["Relaxed Seat Breath"],
    ["Walk Feel"],
    ["alleviating stress"],
    ["helping breathing, satisfaction"],
    ["Relieve Stress, Build Support"],
    ["Relaxation Response"],
    ["Deep Breaths"],
    ["Delete Not Helpful Thoughts"],
    ["Strengthen Helpful"],
    ["Sleep Better and Find Joy"],
    ["Yoga Sleep"],
    ["Relieve Pain"],
    ["Build and Boost Mental Strength"],
    ["Spending Time Outdoors"],
    ["Daily Routine Tasks"],
    ["Feel better each day when you awake by"],
    ["Feel better physically by"],
    ["Practicing mindfulness each day"],
    ["Be happier by"],
    ["Meditation can improve health"],
    ["Spending time outdoors"],
    ["Break the cycle of stress and anxiety"],
    ["Feel calm in stressful situations"],
    ["Deal with work pressure"],
    ["Learn to reduce feelings of overwhelmed"]    
    ]
    
    
def text2text(input_text):
    input_ids = tokenizer(input_text, return_tensors="pt").input_ids

    outputs = model.generate(input_ids, max_length=200)
    return tokenizer.decode(outputs[0])


with gr.Blocks() as demo:
    gr.Markdown(
    """
    # Flan T5 Large Demo
    780M parameter Large language model fine tuned on diverse tasks.
    Prompt the model in the Input box.
    """)
    txt_in = gr.Textbox(label="Input", lines=3)
    correct_label = gr.Label(label="Correct")
    txt_out = gr.Textbox(value="", label="Output", lines=4)
    

    btn = gr.Button(value="Submit")
    btn.click(text2text, inputs=[txt_in], outputs=[txt_out])


    gr.Examples(
        examples=get_examples(),
        inputs=[txt_in,correct_label]
    )
    

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