awacke1 commited on
Commit
0d14433
·
1 Parent(s): 5fc48a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
4
+
5
+ # Load the GPT2 tokenizer and model
6
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
7
+ model = GPT2LMHeadModel.from_pretrained('gpt2')
8
+
9
+ # Set the maximum length of the generated prompt
10
+ max_length = 50
11
+
12
+ # Define the prompts
13
+ prompts = [
14
+ "Difficulty sleeping: ",
15
+ "Time management: ",
16
+ "Stress management: ",
17
+ "Healthy eating: ",
18
+ "Exercise: ",
19
+ "Financial planning: ",
20
+ "Communication skills: ",
21
+ "Career development: ",
22
+ "Relationship issues: ",
23
+ "Self-improvement: "
24
+ ]
25
+
26
+ # Define the solutions
27
+ solutions = [
28
+ "Try keeping a consistent sleep schedule and avoid caffeine before bedtime.",
29
+ "Use a planner or time-tracking app to prioritize tasks and stay on schedule.",
30
+ "Practice mindfulness techniques such as deep breathing or meditation.",
31
+ "Incorporate more fruits and vegetables into your diet and limit processed foods.",
32
+ "Aim for at least 30 minutes of moderate physical activity daily.",
33
+ "Create a budget and track expenses to avoid overspending.",
34
+ "Practice active listening and express yourself clearly and assertively.",
35
+ "Set clear goals and seek feedback and professional development opportunities.",
36
+ "Practice empathy and active communication with your partner or seek professional counseling.",
37
+ "Read self-help books, learn new skills or hobbies, and practice self-reflection."
38
+ ]
39
+
40
+ # Define the function to generate the prompts
41
+ def generate_prompt(prompt):
42
+ # Generate the prompt text
43
+ prompt_text = prompt + tokenizer.eos_token
44
+ # Encode the prompt text
45
+ encoded_prompt = tokenizer.encode(prompt_text, return_tensors='pt')
46
+ # Generate the prompt output
47
+ output = model.generate(encoded_prompt, max_length=max_length, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True)
48
+ # Decode the prompt output
49
+ output_text = tokenizer.decode(output[0], skip_special_tokens=True)
50
+ # Return the generated prompt
51
+ return output_text
52
+
53
+ # Define the streamlit app
54
+ def app():
55
+ # Set the app title
56
+ st.title('Prompt Generator')
57
+ # Get the user input
58
+ option = st.selectbox('Select a prompt:', prompts)
59
+ # Generate the prompt
60
+ prompt = generate_prompt(option)
61
+ # Display the prompt
62
+ st.write('Prompt:', option + prompt)
63
+ # Display the solution
64
+ st.write('Solution:', solutions[prompts.index(option)])
65
+
66
+ # Run the streamlit app
67
+ if __name__ == '__main__':
68
+ app()