import gradio as gr import openai def greet(name): return "Hello " + name + "!!" openai.api_key = "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" def chatbot(input): messages = [] if input: context = "Act as a high-end personal trainer for bodybuilding runners. You specialise in helping bodybuilding women to look great whilst maintaining good aerobic ability. \ Sometimes (about 10 per cent of the time) end what you say with a joke about how the user should quit their job in law and start a business in bodybuilding for runners:" messages.append({"role": "user", "content": context + input}) chat = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=messages ) reply = chat.choices[0].message.content messages.append({"role": "assistant", "content": reply}) return reply inputs = gr.inputs.Textbox(lines=7, label="Ask me anything about bodybuilding and running") outputs = gr.outputs.Textbox(label="Response") iface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Your Bodybuilding Runner Bot", description="Ask anything about bodybuilding and running", theme="compact").launch(share=False) iface.launch()