Spaces:
Runtime error
Runtime error
import gradio as gr | |
from huggingface_hub import secrets | |
import openai | |
# Retrieve the API key from the Secrets Manager | |
openai.api_key = secrets.get("api_key") | |
messages = [{"role": "system", "content": "you are chatGPT"}] | |
def GPTBhai(user_input): | |
messages.append({"role": "user", "content": user_input}) | |
response = openai.ChatCompletion.create( | |
model = "gpt-3.5-turbo", | |
messages = messages | |
) | |
ChatGPT_reply = response["choices"][0]["message"]["content"] | |
messages.append({"role": "assistant", "content": ChatGPT_reply}) | |
return ChatGPT_reply | |
iface = gr.Interface(fn=GPTBhai, inputs = "text", outputs = "text", title = "bhAI") | |
iface.launch() |