awacke1 commited on
Commit
2296bb4
·
1 Parent(s): 7e18848

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -1
app.py CHANGED
@@ -1 +1,79 @@
1
- import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
3
+
4
+ # xl size run out of memory on 16GB vm
5
+ tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
6
+ model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large")
7
+
8
+ title = ""
9
+
10
+ def get_examples ():
11
+ return [
12
+ ["Being a Happier and Healthier Person"],
13
+ ["Learn to Use Mindfulness to Affect Well Being"],
14
+ ["Eating and Drinking - Find Healthy Nutrition Habits"],
15
+ ["Drinking - Find Reasons and Cut Back or Quit Entirely"],
16
+ ["Stress is relieved by quieting your mind, getting exercise and time with nature"],
17
+ ["Reprogram Pain Stress Reactions"],
18
+ ["Brain gamification"],
19
+ ["Mental Body Scan"],
20
+ ["Stretch, Calm, Breath"],
21
+ ["Relaxed Seat Breath"],
22
+ ["Walk Feel"],
23
+ ["alleviating stress"],
24
+ ["helping breathing, satisfaction"],
25
+ ["Relieve Stress, Build Support"],
26
+ ["Relaxation Response"],
27
+ ["Deep Breaths"],
28
+ ["Delete Not Helpful Thoughts"],
29
+ ["Strengthen Helpful"],
30
+ ["Sleep Better and Find Joy"],
31
+ ["Yoga Sleep"],
32
+ ["Relieve Pain"],
33
+ ["Build and Boost Mental Strength"],
34
+ ["Spending Time Outdoors"],
35
+ ["Daily Routine Tasks"],
36
+ ["Feel better each day when you awake by"],
37
+ ["Feel better physically by"],
38
+ ["Practicing mindfulness each day"],
39
+ ["Be happier by"],
40
+ ["Meditation can improve health"],
41
+ ["Spending time outdoors"],
42
+ ["Break the cycle of stress and anxiety"],
43
+ ["Feel calm in stressful situations"],
44
+ ["Deal with work pressure"],
45
+ ["Learn to reduce feelings of overwhelmed"]
46
+ ]
47
+
48
+
49
+ def text2text(input_text):
50
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids
51
+
52
+ outputs = model.generate(input_ids, max_length=200)
53
+ return tokenizer.decode(outputs[0])
54
+
55
+
56
+ with gr.Blocks() as demo:
57
+ gr.Markdown(
58
+ """
59
+ # Flan T5 Large Demo
60
+ 780M parameter Large language model fine tuned on diverse tasks.
61
+ Prompt the model in the Input box.
62
+ """)
63
+ txt_in = gr.Textbox(label="Input", lines=3)
64
+ correct_label = gr.Label(label="Correct")
65
+ txt_out = gr.Textbox(value="", label="Output", lines=4)
66
+
67
+
68
+ btn = gr.Button(value="Submit")
69
+ btn.click(text2text, inputs=[txt_in], outputs=[txt_out])
70
+
71
+
72
+ gr.Examples(
73
+ examples=get_examples(),
74
+ inputs=[txt_in,correct_label]
75
+ )
76
+
77
+
78
+ if __name__ == "__main__":
79
+ demo.launch()