Spaces:
Runtime error
Runtime error
yizhangliu
commited on
Commit
•
3ab5c22
1
Parent(s):
3f8d4e8
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
from pyChatGPT import ChatGPT
|
|
|
2 |
import os
|
3 |
from loguru import logger
|
4 |
|
|
|
|
|
|
|
5 |
def chat(text):
|
6 |
try:
|
7 |
-
session_token = os.environ.get('SessionToken')
|
8 |
-
logger.info(f"session_token_: {session_token}")
|
9 |
api = ChatGPT(session_token)
|
10 |
resp = api.send_message(text)
|
11 |
api.refresh_auth()
|
@@ -16,10 +18,33 @@ def chat(text):
|
|
16 |
response = "Sorry, I'm am tired."
|
17 |
return response
|
18 |
|
19 |
-
|
20 |
-
demo = gr.Interface(chat,
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
demo.launch(debug = True)
|
|
|
1 |
from pyChatGPT import ChatGPT
|
2 |
+
import gradio as gr
|
3 |
import os
|
4 |
from loguru import logger
|
5 |
|
6 |
+
session_token = os.environ.get('SessionToken')
|
7 |
+
logger.info(f"session_token_: {session_token}")
|
8 |
+
|
9 |
def chat(text):
|
10 |
try:
|
|
|
|
|
11 |
api = ChatGPT(session_token)
|
12 |
resp = api.send_message(text)
|
13 |
api.refresh_auth()
|
|
|
18 |
response = "Sorry, I'm am tired."
|
19 |
return response
|
20 |
|
21 |
+
|
22 |
+
# demo = gr.Interface(chat,
|
23 |
+
# inputs = [gr.Textbox(label = 'Input: ')],
|
24 |
+
# outputs = gr.outputs.Textbox(type="text",label="from ChatGPT:"),
|
25 |
+
# title = "Talk with ChatGPT",
|
26 |
+
# description= "")
|
27 |
+
|
28 |
+
def chat(message, history):
|
29 |
+
history = history or []
|
30 |
+
message = message.lower()
|
31 |
+
if message.startswith("how many"):
|
32 |
+
response = random.randint(1, 10)
|
33 |
+
elif message.startswith("how"):
|
34 |
+
response = random.choice(["Great", "Good", "Okay", "Bad"])
|
35 |
+
elif message.startswith("where"):
|
36 |
+
response = random.choice(["Here", "There", "Somewhere"])
|
37 |
+
else:
|
38 |
+
response = "I don't know"
|
39 |
+
history.append((message, response))
|
40 |
+
return history, history
|
41 |
+
|
42 |
+
chatbot = gr.Chatbot().style(color_map=("green", "pink"))
|
43 |
+
demo = gr.Interface(
|
44 |
+
chat,
|
45 |
+
["text", "state"],
|
46 |
+
[chatbot, "state"],
|
47 |
+
allow_flagging="never",
|
48 |
+
)
|
49 |
+
|
50 |
demo.launch(debug = True)
|