File size: 1,062 Bytes
64c6199
6b17378
 
 
 
 
 
 
 
 
 
8a82df0
 
 
6b17378
8a82df0
 
6b17378
 
8a82df0
 
6b17378
 
 
 
 
 
 
 
 
 
8a82df0
6b17378
 
 
8a82df0
6b17378
 
 
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
34
35
36
37
38
39
import subprocess
subprocess.check_call(["pip", "install", "-q openai"])
subprocess.check_call(["pip", "install", "-q gradio", "transformers","python-dotenv","--quiet gradio"])

#!pip install -q openai
#!pip install -q gradio
#!pip install gradio
#!pip install --quiet gradio
#!pip install transformers
#!pip install python-dotenv

import gradio as gr
from transformers import TFAutoModelForCausalLM, AutoTokenizer
import openai

from dotenv import load_dotenv
import os
load_dotenv() # load environment variables from .env file
api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable

def openai_chat(prompt):
completions = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=1024,
n=1,
temperature=0.5,
)

message = completions.choices[0].text
return message.strip()
def chatbot(input, history=[]):
output = openai_chat(input)
history.append((input, output))
return history, history

gr.Interface(fn = chatbot,
inputs = ["text",'state'],
outputs = ["chatbot",'state']).launch(debug = True)