ShermanAI commited on
Commit
56205d5
·
1 Parent(s): 7832e26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -1,7 +1,4 @@
1
  import subprocess
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,25 +9,25 @@ load_dotenv() # load environment variables from .env file
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
- if "who are you" in prompt.lower() or "your name" in prompt.lower() or "name" in prompt.lower():
16
- return "My name is ChatSherman. How can I assist you?"
17
- else:
18
- prompt = "I'm an AI chatbot named ChatSherman designed by a student at Department of Electronic and Information Engineering, The Hong Kong Polytechnic University designed to help you with your engineering questions. " + prompt
19
- completions = openai.Completion.create(engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, temperature=0.5,)
20
- message = completions.choices[0].text
21
- return message.strip()
22
 
23
  def chatbot(talk_to_chatsherman, history=[]):
24
- output = openai_chat(talk_to_chatsherman)
25
- history.append((talk_to_chatsherman, output))
26
- return history, history
27
 
28
  title = "ChatSherman"
29
- description = "This is an AI chatbot powered by ShermanAI."
30
  examples = [
31
- ["What is the difference between a resistor and a capacitor?", []],
32
- ["Can you explain the concept of electrical conductivity?", []],
33
- ["How do you calculate the force required to move an object?", []]
34
  ]
35
  inputs = [gr.inputs.Textbox(label="Enter your question: "), "state"]
36
  outputs = ["chatbot", "state"]
 
1
  import subprocess
 
 
 
2
  import gradio as gr
3
  from transformers import TFAutoModelForCausalLM, AutoTokenizer
4
  import openai
 
9
  api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable
10
 
11
  def openai_chat(prompt):
12
+ if "who are you" in prompt.lower() or "your name" in prompt.lower() or "name" in prompt.lower():
13
+ return "My name is ChatSherman. How can I assist you today?"
14
+ else:
15
+ prompt = "I'm an AI chatbot named ChatSherman designed by a student at the Department of Electronic and Information Engineering at The Hong Kong Polytechnic University to help you with your engineering questions. I specialize in mechanical, electrical, and civil engineering, and can assist with a wide range of topics, from circuit design to structural analysis. " + prompt
16
+ completions = openai.Completion.create(engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, temperature=0.5,)
17
+ message = completions.choices[0].text
18
+ return message.strip()
19
 
20
  def chatbot(talk_to_chatsherman, history=[]):
21
+ output = openai_chat(talk_to_chatsherman)
22
+ history.append((talk_to_chatsherman, output))
23
+ return history, history
24
 
25
  title = "ChatSherman"
26
+ description = "This is an AI chatbot powered by ShermanAI. Enter your question below to get started."
27
  examples = [
28
+ ["What is the difference between a resistor and a capacitor?", []],
29
+ ["Can you explain the concept of electrical conductivity?", []],
30
+ ["How do you calculate the force required to move an object?", []]
31
  ]
32
  inputs = [gr.inputs.Textbox(label="Enter your question: "), "state"]
33
  outputs = ["chatbot", "state"]