File size: 545 Bytes
ed73ed1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import openai
import gradio as gr

# Getting responses using the OpenAI API
def response_chatgpt(api_key, message):
  # OPENAI API KEY
  openai.api_key = api_key
  prompt = (f"{message}")
  response = openai.Completion.create(
      engine="text-davinci-003",
      prompt=prompt,
      max_tokens=1024
  )
  # Displaying the answer on the screen
  result = response["choices"][0]["text"]
  return result
      
# User input
chatbot = gr.Interface(
    fn=response_chatgpt, 
    inputs=["text", "text"],
    outputs="text",
)
chatbot.launch()