Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,38 +9,6 @@ import openai
|
|
9 |
from dotenv import load_dotenv
|
10 |
import os
|
11 |
|
12 |
-
'''
|
13 |
-
load_dotenv() # load environment variables from .env file
|
14 |
-
api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable
|
15 |
-
def predict(message, history):
|
16 |
-
prompt = "I'm an AI chatbot named ChatSherman designed by a super-intelligent student named ShermanAI at the Department of Electronic and Information Engineering at The Hong Kong Polytechnic University to help you with your engineering questions. Also, I can assist with a wide range of topics and questions. I am now version 2.0, which is more powerful than version 1.0, able to do more complex tasks, and optimized for chat. "
|
17 |
-
history = [(prompt, '')] + history
|
18 |
-
history_openai_format = []
|
19 |
-
for human, assistant in history:
|
20 |
-
history_openai_format.append({"role": "user", "content": human })
|
21 |
-
history_openai_format.append({"role": "assistant", "content": assistant})
|
22 |
-
history_openai_format.append({"role": "user", "content": message})
|
23 |
-
response = openai.ChatCompletion.create(
|
24 |
-
model='gpt-3.5-turbo-16k-0613', #gpt-3.5-turbo-0301 faster
|
25 |
-
messages= history_openai_format,
|
26 |
-
temperature=0.5,
|
27 |
-
stream=True
|
28 |
-
)
|
29 |
-
partial_message = ""
|
30 |
-
for chunk in response:
|
31 |
-
if len(chunk['choices'][0]['delta']) != 0:
|
32 |
-
partial_message = partial_message + chunk['choices'][0]['delta']['content']
|
33 |
-
yield partial_message
|
34 |
-
title = "ChatSherman-2.0"
|
35 |
-
description = "Due to the unavailability of an OpenAI key, this chatbot is currently not operational. I apologize for any inconvenience caused. However, you may try using ChatSherman-1.0 at https://huggingface.co/spaces/ShermanAI/ChatSherman for a similar conversational experience. Thank you for your understanding"#"This is an AI chatbot powered by ShermanAI. Enter your question below to get started. "
|
36 |
-
examples = [
|
37 |
-
["What is ChatSherman, and how does it work?", []],
|
38 |
-
["Is my personal information and data safe when I use the ChatSherman chatbot?", []],
|
39 |
-
["What are some common applications of deep learning in engineering?", []]
|
40 |
-
]
|
41 |
-
gr.ChatInterface(predict, title=title, description=description, examples=examples).queue().launch(debug=True)
|
42 |
-
'''
|
43 |
-
|
44 |
title = "ChatSherman-2.0"
|
45 |
description = ("Due to the unavailability of an OpenAI key, this chatbot is currently not operational. "
|
46 |
"However, you may try using ChatSherman-1.0 at "
|
|
|
9 |
from dotenv import load_dotenv
|
10 |
import os
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
title = "ChatSherman-2.0"
|
13 |
description = ("Due to the unavailability of an OpenAI key, this chatbot is currently not operational. "
|
14 |
"However, you may try using ChatSherman-1.0 at "
|