import openai import gradio as gr import random openai.api_key = random.choice(['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', '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', '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', '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', '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', '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', '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', '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', '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', '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', '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']) def completion(prompt): response = openai.Completion.create( engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, stop=None, temperature=0.5 ) return response.choices[0].text[2:] def greet(question): return completion('Please translate this passage into German and then into Chinese.\n'+question) demo = gr.Interface(fn=greet, inputs=gr.Textbox(lines=20, placeholder='Please enter the text to be weighted down'), outputs=gr.Textbox(lines=20, placeholder='It will take some time to reduce the weight, please wait...')) if __name__ == "__main__": # demo.launch(share='True') demo.launch()