Spaces:
Runtime error
Runtime error
import os | |
#os.environ['OPENAI_API_KEY'] = openAI | |
# Retrieve the openAI secret from the environment | |
openai_secret = os.environ.get('openAI') | |
# Set the secret as an environment variable | |
os.environ['OPENAI_API_KEY'] = openai_secret | |
class Prompter: | |
def __init__(self, gpt_model, temper): | |
openai.api_key = openai_secret | |
#os.environ.get("OPENAI_API_KEY") | |
self.gpt_model = gpt_model | |
self.temper = temper | |
def prompt_model_print(self, messages: list): | |
response = openai.ChatCompletion.create(model=self.gpt_model, messages=messages) | |
return response["choices"][0]["message"]["content"] | |
new_emotions_prompt = [ | |
{"role" : "system", "content" : "Act as an inventor of new emotions. Consider the following: Mankind as a whole experiences many" | |
"emotions like happiness, sadness, hate, love, Beauty, and much more. Cultures in particular experience emotions or label emotions other" | |
"cultures don't have words for. So for example in Korea exists an emotion labeled as 'Aegyo' which describes a special kind of behavior" | |
"to make people love you. Or 'German Angst' even attributes a certain facet of anxiety to a nationality. Search for feelings that are part" | |
"of human existence. But these feelings should not have been labeled yet. They exist, but they don't have a label." | |
"Define these feelings and invent a label for each of these feeling. Print the label in a bold typo. Also provide me with an example sentence someone could say and" | |
"explain your reasoning for the word (label) you invented and why you think that this could be a human emotion." | |
"when experiences these feelings. Also provide an antonym. Focus only on the English Language. Display your output in this HTML format: [<li><strong>{Name of the new emotion}</strong>" | |
"<p>{Description of the new emotion}</p><p>Example sentence: {Example sentence}</p><p>Explanation: {Explanation why this could be an interestingly emotion}</p>]"}, | |
{"role" : "user", "content" : "Generate 1 new feeling"}, | |
] | |
import os | |
from google.colab import files | |
from google.colab import drive | |
def emo(name, temper, save_response): | |
prompters = Prompter("gpt-3.5-turbo", temper) | |
response_text = prompters.prompt_model_print(new_emotions_prompt) | |
if save_response: | |
save_response_to_file(response_text) | |
return response_text | |
def save_emotion_output(response_text): | |
with open("/content/drive/MyDrive/emotion_output.html", "a") as file: | |
file.write(response_text) | |
file.write("\n") | |
print("Saved emotion output to emotion_output.html") | |
with gr.Blocks() as demo: | |
with gr.Row(): | |
slider = gr.Slider(0, 1, label='Temperature', | |
info="Choose a float value between 0 and 1 to set the 'creativity' " | |
"of the machine. Keep in mind that a value of 1 (highest) may create inconsistent " | |
"but also interesting results.") | |
emo_out = gr.Textbox(value='text', label="Output", lines=3) | |
#save_btn = gr.Button(label="Save Emotion") | |
with gr.Row(): | |
btn = gr.Button(value="Generate Emotion") | |
btn.click(emo, inputs=slider, outputs = emo_out) | |
save_btn = gr.Button(value="Save Emotion") | |
save_btn.click(save_emotion_output, inputs=emo_out) | |
if __name__ == "__main__": | |
demo.launch() | |