awacke1 commited on
Commit
b0dae41
·
1 Parent(s): 46a0da3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+ from transformers import pipeline
4
+
5
+ # Load the GPT2 model
6
+ generator = pipeline('text-generation', model='gpt2')
7
+
8
+ # Set the maximum length of the generated prompt
9
+ max_length = 50
10
+
11
+ # Define the prompts and solutions
12
+ prompts = {
13
+ "Difficulty sleeping": [
14
+ "Try keeping a consistent sleep schedule and avoid caffeine before bedtime.",
15
+ "Make your bedroom a comfortable and calming environment.",
16
+ "Avoid using electronic devices before bedtime.",
17
+ "Try relaxation techniques like deep breathing or meditation.",
18
+ "Consider talking to a healthcare provider if sleep problems persist."
19
+ ],
20
+ "Time management": [
21
+ "Use a planner or time-tracking app to prioritize tasks and stay on schedule.",
22
+ "Break down large tasks into smaller ones.",
23
+ "Limit multitasking and focus on one task at a time.",
24
+ "Delegate tasks to others when possible.",
25
+ "Take regular breaks and avoid overworking yourself."
26
+ ],
27
+ "Stress management": [
28
+ "Practice mindfulness techniques such as deep breathing or meditation.",
29
+ "Get regular exercise to reduce stress and improve mood.",
30
+ "Get enough sleep and practice good sleep habits.",
31
+ "Take breaks throughout the day to reduce stress levels.",
32
+ "Try to identify the sources of stress in your life and develop strategies to manage them."
33
+ ]
34
+ }
35
+
36
+ # Define the function to generate the prompts and solutions
37
+ def generate_prompt(prompt):
38
+ # Get a random solution for the prompt
39
+ solution = random.choice(prompts[prompt])
40
+ # Generate the prompt text
41
+ prompt_text = f"What can I do to {prompt.lower()}? "
42
+ # Generate the prompt output
43
+ output = generator(prompt_text, max_length=max_length, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True)
44
+ # Decode the prompt output
45
+ output_text = output[0]['generated_text'][len(prompt_text):].strip()
46
+ # Return the generated prompt and solution
47
+ return output_text, solution
48
+
49
+ # Define the streamlit app
50
+ def app():
51
+ # Set the app title
52
+ st.title('ICL-LM Interface')
53
+ # Get the user input
54
+ option = st.selectbox('Select a problem:', list(prompts.keys()))
55
+ # Generate the prompt and solution
56
+ prompt, solution = generate_prompt(option)
57
+ # Display the prompt
58
+ st.write('Prompt:', prompt)
59
+ # Display the solution
60
+ st.write('Solution:', solution)
61
+
62
+ # Run the streamlit app
63
+ if __name__ == '__main__':
64
+ while True:
65
+ app()