Spaces:
Runtime error
Runtime error
Download app.py from Aavinos/SiteChatBot: direct link, hf CLI and curl.
- Browser
- Download file 794 Bytes
-
https://huggingface.co/spaces/Aavinos/SiteChatBot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Aavinos/SiteChatBot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Aavinos/SiteChatBot/resolve/main/app.py
794 Bytes
| import os | |
| import openai | |
| import gradio as gr | |
| openai.api_key = os.environ["OPENAI_API_KEY"] | |
| messages = [ | |
| {"role": "system", "content": "You are a helpful and kind AI Assistant."}, | |
| ] | |
| 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 AI") | |
| outputs = gr.outputs.Textbox(label="Reply") | |
| gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI Chatbot", | |
| description="Ask anything you want", | |
| theme="compact").launch() | |