Spaces:
Runtime error
Runtime error
Create backup.app.py
Browse files- backup.app.py +54 -0
backup.app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
from transformers import pipeline
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
generator = pipeline('text-generation', model='gpt2')
|
7 |
+
max_length = 50
|
8 |
+
|
9 |
+
prompts = {
|
10 |
+
"Difficulty sleeping": [
|
11 |
+
"Try keeping a consistent sleep schedule and avoid caffeine before bedtime.",
|
12 |
+
"Make your bedroom a comfortable and calming environment.",
|
13 |
+
"Avoid using electronic devices before bedtime.",
|
14 |
+
"Try relaxation techniques like deep breathing or meditation.",
|
15 |
+
"Consider talking to a healthcare provider if sleep problems persist."
|
16 |
+
],
|
17 |
+
"Time management": [
|
18 |
+
"Use a planner or time-tracking app to prioritize tasks and stay on schedule.",
|
19 |
+
"Break down large tasks into smaller ones.",
|
20 |
+
"Limit multitasking and focus on one task at a time.",
|
21 |
+
"Delegate tasks to others when possible.",
|
22 |
+
"Take regular breaks and avoid overworking yourself."
|
23 |
+
],
|
24 |
+
"Stress management": [
|
25 |
+
"Practice mindfulness techniques such as deep breathing or meditation.",
|
26 |
+
"Get regular exercise to reduce stress and improve mood.",
|
27 |
+
"Get enough sleep and practice good sleep habits.",
|
28 |
+
"Take breaks throughout the day to reduce stress levels.",
|
29 |
+
"Try to identify the sources of stress in your life and develop strategies to manage them."
|
30 |
+
]
|
31 |
+
}
|
32 |
+
|
33 |
+
def generate_prompt(prompt):
|
34 |
+
solution = random.choice(prompts[prompt])
|
35 |
+
prompt_text = f"What can I do to {prompt.lower()}? "
|
36 |
+
output = generator(prompt_text, max_length=max_length, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True)
|
37 |
+
output_text = output[0]['generated_text'][len(prompt_text):].strip()
|
38 |
+
return prompt_text, output_text, solution
|
39 |
+
|
40 |
+
st.title('ICL-LM Interface')
|
41 |
+
option = st.selectbox('Select a problem:', list(prompts.keys()))
|
42 |
+
|
43 |
+
if st.button('Generate Prompt and Solution'):
|
44 |
+
results = []
|
45 |
+
for _ in range(3):
|
46 |
+
prompt_text, prompt, solution = generate_prompt(option)
|
47 |
+
results.append([prompt_text, prompt, solution])
|
48 |
+
|
49 |
+
with open('results.txt', 'a') as f:
|
50 |
+
for result in results:
|
51 |
+
f.write(f"{result[0]}\t{result[1]}\t{result[2]}\n")
|
52 |
+
|
53 |
+
df = pd.read_csv('results.txt', sep='\t', header=None, names=['Input', 'Prompt', 'Solution'])
|
54 |
+
st.write(df)
|