Spaces:
Runtime error
Runtime error
!pip install openai | |
import gradio as gr | |
import openai | |
# Initialize the API key | |
openai.api_key = "YOUR_API_KEY" | |
def generate_text(prompt): | |
completions = openai.Completion.create( | |
engine="text-davinci-002", | |
prompt=prompt, | |
max_tokens=1024, | |
n=1, | |
stop=None, | |
temperature=0.5, | |
) | |
message = completions.choices[0].text | |
return message.strip() | |
inputs = gr.inputs.Textbox(lines=1, label="Enter your message:") | |
outputs = gr.outputs.Textbox(label="Response:") | |
interface = gr.Interface( | |
generate_text, | |
inputs, | |
outputs, | |
title="GPT-3 Chatbot", | |
description="A chatbot powered by GPT-3" | |
) | |
demo.launch() | |