File size: 748 Bytes
676f49f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai
import gradio as gr

# Getting responses using the OpenAI API
def answer_chatgpt(api_key, message):
  # OPENAI API KEY
  openai.api_key = api_key
  prompt = (f"You are GPT-3 and answer my following message: {message}")
  response = openai.Completion.create(
      engine="text-davinci-003",
      prompt=prompt,
      max_tokens=1024
  )
  # Displaying the answer on the screen
  answer = response["choices"][0]["text"]
  return answer
      
# User input
chatbot = gr.Interface(
    fn=answer_chatgpt, 
    inputs=["text", "text"],
    outputs="text",
    title="πŸ€– ChatGPT-Python 🐍",
    description="ChatGPT-Python is a software that allows you to talk to GPT-3 with a web interface using the openai api"
)
chatbot.launch()