Spaces:
Runtime error
Runtime error
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) |