import gradio as gr import os from transformers import pipeline title = "📗Health and Mindful Story Gen❤️" # Define the examples to show in the interface 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"] ] # Initialize the models using Hugging Face pipelines generator1 = pipeline("text-generation", model="gpt2-large") generator2 = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B") generator3 = pipeline("text-generation", model="EleutherAI/gpt-j-6B") 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, max_length=50)[0]['generated_text'] out2 = generator2(input_text, max_length=50)[0]['generated_text'] out3 = generator3(input_text, max_length=50)[0]['generated_text'] 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, examples_per_page=100) demo.launch(share=False)