Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,24 +12,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 |
-
|
|
|
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(
|
21 |
-
|
22 |
-
|
23 |
-
return history, history
|
24 |
|
25 |
-
title = "ChatSherman"
|
26 |
-
description = "This is an AI chatbot powered by ShermanAI
|
27 |
examples = [
|
28 |
-
["What is the
|
29 |
-
["Can you explain the concept of electrical conductivity?"
|
30 |
-
["
|
31 |
]
|
32 |
-
inputs = [gr.inputs.Textbox(label="Enter your question: ")
|
33 |
-
outputs =
|
|
|
34 |
interface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
|
35 |
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 |
+
topics = ["engineering", "science", "math", "IT", "history", "English"]
|
16 |
+
prompt = f"Hello! My name is ChatSherman and I'm an AI chatbot designed to help you with your questions in {', '.join(topics)}. {prompt}"
|
17 |
completions = openai.Completion.create(engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, temperature=0.5,)
|
18 |
message = completions.choices[0].text
|
19 |
return message.strip()
|
20 |
|
21 |
+
def chatbot(question):
|
22 |
+
response = openai_chat(question)
|
23 |
+
return response
|
|
|
24 |
|
25 |
+
title = "ChatSherman - AI Chatbot"
|
26 |
+
description = "This is an AI chatbot powered by ShermanAI"
|
27 |
examples = [
|
28 |
+
["What is the Pythagorean theorem?"],
|
29 |
+
["Can you explain the concept of electrical conductivity?"],
|
30 |
+
["Who was the first president of the United States?"],
|
31 |
]
|
32 |
+
inputs = [gr.inputs.Textbox(label="Enter your question: ")]
|
33 |
+
outputs = gr.outputs.Textbox(label="ChatSherman's Response:")
|
34 |
+
|
35 |
interface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
|
36 |
interface.launch(debug=True)
|