File size: 757 Bytes
4f62f50
53a9fc0
 
4f62f50
 
53a9fc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f62f50
53a9fc0
4f62f50
 
 
53a9fc0
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
import gradio as gr
import openai


# Getting responses using the OpenAI API
def response_chatgpt(api_key, message: str):
    # OPENAI API KEY
    openai.api_key = api_key
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=message,
        max_tokens=1024,
        stream=False,
    )
    # Choosing best conversation
    completion_text = ''
    # iterate through the stream of events
    for event in response:
        event_text = event['choices'][0]['text']  # extract the text
        completion_text += event_text  # append the text

    return completion_text


# User input and web interface
chatbot = gr.Interface(
    fn=response_chatgpt,
    inputs=["text", "text"],
    outputs="text",
)
chatbot.launch()