import openai import gradio as gr from gradio import HuggingFaceDatasetSaver openai.api_key ='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' def openai_chat(prompt): completions = openai.Completion.create( engine="text-davinci-003", prompt=prompt+"The following is the prompt from teacher working in canvas infrastructure", max_tokens=1024, n=1, temperature=0.5, frequency_penalty=0, presence_penalty=0.6, stop=[" Human:", " AI:"] ) message = completions.choices[0].text return message.strip() def chatbot(input, history=[]): output = openai_chat(input) history.append((input, output)) return history, history gr.Interface(fn = chatbot, inputs = ["text",'state'], outputs = ["chatbot",'state'], examples=[["Building a translation demo with Gradio is so easy!", "eng_Latn", "spa_Latn"]], cache_examples=False, title="Demo app", allow_flagging="manual").launch()