File size: 677 Bytes
206002f
002afcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206002f
002afcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
!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()