Spaces:
Runtime error
Runtime error
Commit ·
2f30cc1
1
Parent(s): 0515673
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,26 @@ import random
|
|
| 7 |
session_token = os.environ.get('SessionToken')
|
| 8 |
logger.info(f"session_token_: {session_token}")
|
| 9 |
|
| 10 |
-
def chat(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
try:
|
| 12 |
api = ChatGPT(session_token)
|
| 13 |
resp = api.send_message(text)
|
|
@@ -18,25 +37,19 @@ def chat(text):
|
|
| 18 |
except:
|
| 19 |
response = "Sorry, I'm am tired."
|
| 20 |
return response
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# demo = gr.Interface(chat,
|
| 24 |
-
# inputs = [gr.Textbox(label = 'Input: ')],
|
| 25 |
-
# outputs = gr.outputs.Textbox(type="text",label="from ChatGPT:"),
|
| 26 |
-
# title = "Talk with ChatGPT",
|
| 27 |
-
# description= "")
|
| 28 |
-
|
| 29 |
def chat(message, history):
|
| 30 |
history = history or []
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
history.append((message, response))
|
| 41 |
return history, history
|
| 42 |
|
|
|
|
| 7 |
session_token = os.environ.get('SessionToken')
|
| 8 |
logger.info(f"session_token_: {session_token}")
|
| 9 |
|
| 10 |
+
# def chat(text):
|
| 11 |
+
# try:
|
| 12 |
+
# api = ChatGPT(session_token)
|
| 13 |
+
# resp = api.send_message(text)
|
| 14 |
+
# api.refresh_auth()
|
| 15 |
+
# api.reset_conversation()
|
| 16 |
+
# response = resp['message']
|
| 17 |
+
# logger.info(f"response_: {response}")
|
| 18 |
+
# except:
|
| 19 |
+
# response = "Sorry, I'm am tired."
|
| 20 |
+
# return response
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# demo = gr.Interface(chat,
|
| 24 |
+
# inputs = [gr.Textbox(label = 'Input: ')],
|
| 25 |
+
# outputs = gr.outputs.Textbox(type="text",label="from ChatGPT:"),
|
| 26 |
+
# title = "Talk with ChatGPT",
|
| 27 |
+
# description= "")
|
| 28 |
+
|
| 29 |
+
def get_response_from_chatbot(text):
|
| 30 |
try:
|
| 31 |
api = ChatGPT(session_token)
|
| 32 |
resp = api.send_message(text)
|
|
|
|
| 37 |
except:
|
| 38 |
response = "Sorry, I'm am tired."
|
| 39 |
return response
|
| 40 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def chat(message, history):
|
| 42 |
history = history or []
|
| 43 |
+
response = get_response_from_chatbot(message)
|
| 44 |
+
# message = message.lower()
|
| 45 |
+
# if message.startswith("how many"):
|
| 46 |
+
# response = random.randint(1, 10)
|
| 47 |
+
# elif message.startswith("how"):
|
| 48 |
+
# response = random.choice(["Great", "Good", "Okay", "Bad"])
|
| 49 |
+
# elif message.startswith("where"):
|
| 50 |
+
# response = random.choice(["Here", "There", "Somewhere"])
|
| 51 |
+
# else:
|
| 52 |
+
# response = "I don't know"
|
| 53 |
history.append((message, response))
|
| 54 |
return history, history
|
| 55 |
|