ShermanAI commited on
Commit
148cfd6
·
1 Parent(s): 4504366

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -2,7 +2,6 @@ import subprocess
2
  subprocess.check_call(["pip", "install", "-q", "openai"])
3
  subprocess.check_call(["pip", "install", "-q", "gradio", "transformers", "python-dotenv"])
4
 
5
- import subprocess
6
  import gradio as gr
7
  from transformers import TFAutoModelForCausalLM, AutoTokenizer
8
  import openai
@@ -13,7 +12,7 @@ load_dotenv() # load environment variables from .env file
13
  api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable
14
 
15
  def openai_chat(prompt):
16
- completions = openai.Completion.create(engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, temperature=0.4,)
17
  message = completions.choices[0].text
18
  return message.strip()
19
 
@@ -22,8 +21,14 @@ def chatbot(input, history=[]):
22
  history.append((input, output))
23
  return history, history
24
 
25
- title = "ChatSherman"
 
 
 
 
 
 
26
  inputs = ["text", "state"]
27
  outputs = ["chatbot", "state"]
28
- interface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=title)
29
  interface.launch(debug=True)
 
2
  subprocess.check_call(["pip", "install", "-q", "openai"])
3
  subprocess.check_call(["pip", "install", "-q", "gradio", "transformers", "python-dotenv"])
4
 
 
5
  import gradio as gr
6
  from transformers import TFAutoModelForCausalLM, AutoTokenizer
7
  import openai
 
12
  api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable
13
 
14
  def openai_chat(prompt):
15
+ completions = openai.Completion.create(engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, temperature=0.5,)
16
  message = completions.choices[0].text
17
  return message.strip()
18
 
 
21
  history.append((input, output))
22
  return history, history
23
 
24
+ title = "My Chatbot Title"
25
+ description = "This is a chatbot powered by OpenAI's GPT-3 model."
26
+ examples = [
27
+ ["Hello, how are you?", []],
28
+ ["What's the meaning of life?", []],
29
+ ["Tell me a joke.", []]
30
+ ]
31
  inputs = ["text", "state"]
32
  outputs = ["chatbot", "state"]
33
+ interface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
34
  interface.launch(debug=True)