Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,13 +12,9 @@ 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 |
-
|
16 |
-
|
17 |
-
|
18 |
-
prompt = "I'm an AI chatbot named ShermanAI 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)
|
@@ -26,27 +22,13 @@ def chatbot(talk_to_chatsherman, history=[]):
|
|
26 |
return history, history
|
27 |
|
28 |
title = "ChatSherman"
|
29 |
-
description = "This is an AI chatbot powered by ShermanAI."
|
30 |
examples = [
|
31 |
-
["
|
32 |
-
["
|
33 |
-
["
|
34 |
]
|
35 |
-
inputs = [gr.inputs.Textbox(label="
|
36 |
outputs = ["chatbot", "state"]
|
37 |
interface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
|
38 |
-
|
39 |
-
# Modify the infer method to add JavaScript code to reset the input textbox value on the client side
|
40 |
-
def reset_input():
|
41 |
-
return """
|
42 |
-
<script>
|
43 |
-
function resetInput() {
|
44 |
-
document.getElementById("input-textbox").value = "";
|
45 |
-
}
|
46 |
-
document.querySelector('[type="submit"]').addEventListener("click", resetInput);
|
47 |
-
</script>
|
48 |
-
"""
|
49 |
-
|
50 |
-
interface.infer = lambda x: (x[0], x[1], reset_input())
|
51 |
-
|
52 |
interface.launch(debug=True)
|
|
|
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 |
|
19 |
def chatbot(talk_to_chatsherman, history=[]):
|
20 |
output = openai_chat(talk_to_chatsherman)
|
|
|
22 |
return history, history
|
23 |
|
24 |
title = "ChatSherman"
|
25 |
+
description = "This is an AI chatbot powered by ShermanAI using 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 = [gr.inputs.Textbox(label="Talk to ChatSherman: "), "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)
|