ChatSherman2.0 / app.py
ShermanAI's picture
Update app.py
36694ba
raw
history blame
860 Bytes
import subprocess
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
title = "My Chatbot Title"
inputs = ["text", "state"]
outputs = ["chatbot", "state"]
interface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=title)
interface.launch(debug=True)