ellen_ai / app.py
laurelix's picture
Upload folder using huggingface_hub
eb00604
Raw
History Blame Contribute Delete
1.17 kB
# Build a chatbot with interface using GPT-3 Key: OpenAI API Key
import openai
import gradio as gr
from dotenv import load_dotenv
import os
load_dotenv()
openai.api_key = os.getenv('OPENAI_KEY')
messages = [
{"role": "system", "content": "You are a helpful and kind AI Assistant created by Livia Ellen, a data scientist with 5 years experience of Python programming. For more information about her you can go to her website liviaellen.com, To contact her, please reach liviaellen@msn.com . She likes paragliding and traveling."},
]
def chatbot(input):
if input:
messages.append({"role": "user", "content": 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="Chat with Ellen-GPT")
outputs = gr.outputs.Textbox(label="Reply")
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Ellen AI Assistant",
description="Ask anything you want",
theme=gr.themes.Soft()).launch()