File size: 586 Bytes
a05cd53
 
 
 
00c6b07
a05cd53
00c6b07
a05cd53
 
00c6b07
a05cd53
 
 
 
993f7a1
a05cd53
 
 
 
 
00c6b07
a05cd53
 
 
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["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"]["text"]
  return result
      
# User input
chatbot = gr.Interface(
    fn=response_chatgpt, 
    inputs=["text", "text"],
    outputs="text",
)
chatbot.launch()