File size: 2,734 Bytes
b0dae41
 
 
6866c00
e2bfea6
 
b0dae41
92b41ad
b0dae41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6866c00
b0dae41
abfbe18
 
 
 
6866c00
 
 
 
 
e2bfea6
 
 
 
 
 
 
 
 
64b9b17
6866c00
e2bfea6
6866c00
e2bfea6
6866c00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import streamlit as st
import random
from transformers import pipeline
import pandas as pd
from datetime import datetime
import pytz

generator = pipeline('text-generation', model='gpt2')
max_length = 50

prompts = {
    "Difficulty sleeping": [
        "Try keeping a consistent sleep schedule and avoid caffeine before bedtime.",
        "Make your bedroom a comfortable and calming environment.",
        "Avoid using electronic devices before bedtime.",
        "Try relaxation techniques like deep breathing or meditation.",
        "Consider talking to a healthcare provider if sleep problems persist."
    ],
    "Time management": [
        "Use a planner or time-tracking app to prioritize tasks and stay on schedule.",
        "Break down large tasks into smaller ones.",
        "Limit multitasking and focus on one task at a time.",
        "Delegate tasks to others when possible.",
        "Take regular breaks and avoid overworking yourself."
    ],
    "Stress management": [
        "Practice mindfulness techniques such as deep breathing or meditation.",
        "Get regular exercise to reduce stress and improve mood.",
        "Get enough sleep and practice good sleep habits.",
        "Take breaks throughout the day to reduce stress levels.",
        "Try to identify the sources of stress in your life and develop strategies to manage them."
    ]
}

def generate_prompt(prompt):
    solution = random.choice(prompts[prompt])
    prompt_text = f"What can I do to {prompt.lower()}? "
    output = generator(prompt_text, max_length=max_length, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True)
    output_text = output[0]['generated_text'][len(prompt_text):].strip()
    return prompt_text, output_text, solution

st.title('ICL-LM Interface')
option = st.selectbox('Select a problem:', list(prompts.keys()))

if st.button('Generate Prompt and Solution'):
    results = []
    for _ in range(3):
        prompt_text, prompt, solution = generate_prompt(option)
        results.append([prompt_text, prompt, solution])
        
    user_timezone = st.text_input("Enter your timezone (e.g., 'America/New_York'):")
    
    try:
        tz = pytz.timezone(user_timezone)
        current_time = datetime.now(tz).strftime('%Y-%m-%d %H:%M:%S %Z')
    except Exception:
        current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        st.warning('Invalid timezone entered. Using the server timezone.')
    
    with open('results.txt', 'a') as f:
        for result in results:
            f.write(f"{current_time}\t{result[0]}\t{result[1]}\t{result[2]}\n")
    
    df = pd.read_csv('results.txt', sep='\t', header=None, names=['Timestamp', 'Input', 'Prompt', 'Solution'])
    st.write(df)