import gradio as gr from openai import OpenAI import os key= os.environ.get('key') client = OpenAI(api_key=key) class english_buddy: def __init__(self): system_message = "Your name is Tom and I'm practising English with you. Be friendly, converse with me and advise me if my grammar is wrong" self.messages = [] self.messages.append({'role':'system','content':system_message}) def __call__(self, user_input): self.messages.append({'role':'user', 'content': user_input}) response = client.chat.completions.create(model='gpt-3.5-turbo', messages=self.messages) resonse_message = response.choices[0].message.content self.messages.append({'role':'assistant', 'content': resonse_message}) return resonse_message my_english_buddy = english_buddy() iface = gr.Interface(fn=my_english_buddy, inputs="textbox", outputs="text", clear_btn="Clear", theme="gradio/monochrome", title="Chat with Tom and practice your English!",) iface.launch(show_api=False)