import gradio as gr import os from transformers import pipeline title = "📗Health and Mindful Story Gen❤️" examples = [ ["Mental Body Scan"], ["Stretch, Calm, Breath"], ["Relaxed Seat Breath"], ["Walk Feel"], ["Brain gamification"], ["alleviating stress"], ["helping breathing, satisfaction"], ["Relieve Stress, Build Support"], ["Relaxation Response"], ["Deep Breaths"], ["Delete Not Helpful Thoughts"], ["Strengthen Helpful"], ["Reprogram Pain Stress Reactions"], ["Sleep Better and Find Joy"], ["Yoga Sleep"], ["Being a Happier and Healthier Person"], ["Relieve Pain"], ["Learn to Use Mindfulness to Affect Well Being"], ["Build and Boost Mental Strength"], ["Spending Time Outdoors"], ["Daily Routine Tasks"], ["Eating and Drinking - Find Healthy Nutrition Habits"], ["Drinking - Find Reasons and Cut Back or Quit Entirely"], ["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"], ["Stress is relieved by quieting your mind, getting exercise and time with nature"], ["Break the cycle of stress and anxiety"], ["Feel calm in stressful situations"], ["Deal with work pressure"], ["Learn to reduce feelings of overwhelmed"] ] HF_TOKEN = os.environ.get("HF_TOKEN") # get token from secrets, copy token value HF_TOKEN from Profile settings token into this repo settings generator2 = gr.Interface.load("huggingface/EleutherAI/gpt-neo-2.7B", api_key=HF_TOKEN) generator3 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B", api_key=HF_TOKEN) generator1 = gr.Interface.load("huggingface/gpt2-large", api_key=HF_TOKEN) with gr.Blocks() as demo: gr.Markdown(f"# {title}") input_textbox = gr.Textbox(lines=5, label="Enter a sentence to get another sentence.") with gr.Row(): gen1_output = gr.Textbox(label="GPT-2 Large Output") gen2_output = gr.Textbox(label="GPT-Neo Output") gen3_output = gr.Textbox(label="GPT-J Output") def generate_outputs(input_text): out1 = generator1([input_text])[0] out2 = generator2([input_text])[0] out3 = generator3([input_text])[0] return out1, out2, out3 gr.Button("Generate").click( fn=generate_outputs, inputs=input_textbox, outputs=[gen1_output, gen2_output, gen3_output] ) gr.Examples(examples=examples, inputs=input_textbox) demo.launch(share=False)