File size: 2,869 Bytes
db05837
 
 
 
86f0b5f
 
 
 
 
db05837
 
 
86f0b5f
 
 
739dec8
db05837
 
 
2b0641b
a490fc1
2b0641b
 
89e5b84
a490fc1
 
db05837
ecbbd4b
2b0641b
 
 
db05837
 
 
 
 
 
 
07933be
7a70b07
db05837
a5e764a
 
db05837
86f0b5f
 
 
 
 
 
 
 
 
 
 
2b0641b
 
 
a490fc1
2b0641b
d4f2291
dcbf1c4
d4f2291
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
import streamlit as st
import cohere
import os


EXAMPLES = {
    "I lost my Job": ("I lost my Job."),
    "I lost my Dog": ("I lost my Dog."),
}
co = cohere.Client(os.getenv('COHERE_API_KEY')) 

# Initialization
def fill_example_caption(**kwargs):
    print(f"Called with {kwargs}")
    print(f"selectbox {prompt}")

def generate_hashtags(input):
    if len(input) == 0:
        return None
    
    if category == "growth":
        input_prompt = "This program will take a sentence as input and reframe it with positive and growth mindset.\n--\nInput: I have a lot of work to do today.\nOutput: I have a lot of work to do today. It's better for me to make a list and break it down into smaller chunks and finish them off one by one.\n--\nInput: I am barely able to lift 10 pound weights.\nOutput: I should exercise more consistently and gradually increase my weight limit. I should also try eating healthy foods.\n--\nInput: {}\nOutput:".format(input.strip())
    if category == "remove_negations":
        input_prompt = "This program takes an input and reframes it by removing negative words and rephrasing with with positivity while preserving the meaning of the original sentence. The word 'no' doesn't appear in the output\n--\nInput: I wouldn’t say I don’t want to go.\nOutput: I would like to go.\n--\nInput: That’s not a bad idea.\nOutput: That is a good idea.\n--\nInput: {}\nOutput:".format(input.strip())
    if category == "self_affirmation":
        input_prompt = "This program takes an input and reframes it with positive affirmations.\n-- \nInput: I am worthless\nOutput: I have value and my actions impact the world around me.\n--\nInput: I am a failure\nOutput: I never fail, only my attempts do. I will keep trying and improving\n--\nInput:  I don’t like myself\nOutput: I accept myself and improve what I can.\n--\nInput: {}\nOutput:".format(input.strip())
    response = co.generate( 
    model='xlarge', 
    prompt=input_prompt, 
    max_tokens=100, 
    temperature=0.9, 
    k=0, 
    p=1, 
    frequency_penalty=0, 
    presence_penalty=0, 
    stop_sequences=["--"], 
    return_likelihoods='NONE') 
    
    output = response.generations[0].text
    return output

st.title('Positive Reframing Generator')
st.write('''This is a simple **Streamlit** app that generates the input sentence with a positive spin to it''')

prompts = ["Choose"] + list(EXAMPLES.keys())
prompt = st.selectbox(
    'Examples (select from this list)',
    prompts,
    index=0,
)
if prompt == "Choose":
    input_val = ""
else:
    input_val = EXAMPLES[prompt]
input = st.text_area('Enter your post title caption or select from examples', input_val, height=100)

category = st.radio(
    "Please select a category",
    ('growth', 'remove_negations', 'self_affirmation'))

if st.button('Reframe'):
    output = generate_hashtags(input)
    st.write(output)