Via Button click (Gradio Interface) I want to output the return value of a method of the Prompter Class:
class Prompter:
def __init__(self, gpt_model, temper):
if not os.environ.get("OPENAI_API_KEY"):
raise Exception("Please set the OPENAI_API_KEY environment variable")
openai.api_key = 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"]
I instantiate an Object of this class within the code for my gradio interface:
import gradio as gr def emo(name):
return prompter.prompt_model_print(emo_name_prompts)
inputs = gr.inputs.Textbox(label="Name")
outputs = gr.outputs.Textbox(label="Emotion")
demo = gr.Interface(fn=emo, inputs=None, outputs=outputs, title="Discover Emotion", description="Please generate a Python list of 10 new feelings, provide name and sentiment")
demo.launch(share=True)
The display appears in my colab cell. When clicking the "generate" button the machine is busy. But it outputs nothing and also my Open AI usage do not change. How do I display the output of prompter.prompt_model_print(emo_name_prompts)
You can assume, that this method works – but only outside of the Gradio interface.