Spaces:
Runtime error
Runtime error
yizhangliu
commited on
Commit
•
5301720
1
Parent(s):
17c6221
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,24 @@
|
|
1 |
from pyChatGPT import ChatGPT
|
2 |
import os
|
|
|
3 |
|
4 |
-
|
5 |
-
def read_token():
|
6 |
-
session_token_text="eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..rZTgbQYSLSN-fX8o.N74lAfJIiSxsXjb6I8EEIQscpXJpSXdTOfUmUTTeqnhRxmuVCuAz_lFcrk8_9H7Pk4dWGKQaxW4EViyWXfp8tgiuQJZJCMd9N-2mKouGIKQWxXYaaHnJwusalk1Opl2pjCWerIvWlRDC5kG5-C0iRrxNd3hgFoRURRBcQXm_Fk7B2TO6jIoVdGdpA61MbwesIAxn1NkgZYpxVTUc847a0LByWdx5r0PVgymxbOfidLtIdA3T6nPXnxjI1qkxiQH7Xts7II_GiNcRnQ69-686E_JW3PFmez-LhEZiSOYMriMbqdZh_szrtFIofZPW4mX6BzyTQODay4li5-0RCiarzbZId2fjbylFuq3z6TfTnCyhloYIG_h0fJ0JECWE6jKnEkIg--pdQwtnDqEYdfxm2m0iYSrxqpPioCiB2qN6s4sYLQ-u0G7dPc9zFN50V8tMfPHkoaIh7TGLoCJSuqe0cEs1x2wVVMDunmnVBMSdfKhF1NizInKZ9ojiL7fgrRggw-Rz0zXdHjMFfCI9n0ZaWM3AUZPJoB2ZUT24_bYjaMDce-2cdrhJQGYiMKSq2dK0xiyklKZ9_2naqShyAMkstDR7SHelsfesTn7zmQO2KxOMwyxwKSB8rTY3GCftIwItJRVCtxxE8z5-21joDa1sujixO8Fq2UGmZiq0CpY-5lpo_a3bUr-Ut1rNmN_1zukPdVfLiL-a9YoCWr7H8bDCerk54gFdArtUZ7kF47DzgxDcvSdtCho5H26h0OAkJ125cbHIrTiotoRpzsaUxtsqv-gsucYZfyTaTq76TwC8X0rpJPljK6hGfu9U_nC5u0QLVQfaINO1PR9IyzsFmgd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cHjmirfjvOLzSbg03Gj5peZ_7N0g-JlHU36nQuZwizQEzOxR1-qH1YC2zFsmQ-VfnRSfKzTOcbZkaubks4c2XzqFckEygiqGDBi9wqMicfSTROdC4E_UXY0t4XQIdJC5HcGYQwgIYF0QdJJUBgvClSyuS9DIpbAckLj_BlfOLsfBnSsRd1oNvj1VTQSqq_7nT0Bv1u0cMeQy_3WGPAAdHvi8GP_qFxS6XqYr8luQc7_KhMIytY2fEFJISjZRpRr1zOu3qYGAiSXx9Emd7NAvjY1v0cQn11-vqdlZRM1Qz7lY8bexnOkfjjKVBQ5otsJ9s7sR5LU._A5iHP30u_uJKApc_1-TLg"
|
7 |
-
|
8 |
-
# with open("session_token.txt") as fd:
|
9 |
-
# session_token = fd.read()
|
10 |
-
|
11 |
-
return session_token_text
|
12 |
-
|
13 |
-
|
14 |
-
def chat(text,session_tokenz):
|
15 |
-
|
16 |
try:
|
17 |
-
|
18 |
-
|
19 |
-
session_token = read_token()
|
20 |
-
|
21 |
api = ChatGPT(session_token)
|
22 |
-
resp = api.send_message(text)
|
23 |
-
|
24 |
api.refresh_auth()
|
25 |
api.reset_conversation()
|
26 |
-
|
|
|
27 |
except:
|
28 |
-
|
29 |
-
|
30 |
-
resp = api.send_message(text)
|
31 |
-
|
32 |
-
api.refresh_auth()
|
33 |
-
api.reset_conversation()
|
34 |
-
|
35 |
-
return xyz
|
36 |
-
|
37 |
|
38 |
-
|
39 |
import gradio as gr
|
40 |
-
gr.Interface(chat,
|
41 |
-
inputs = [gr.Textbox(label = '
|
42 |
-
gr.Textbox(label
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
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 |
api = ChatGPT(session_token)
|
9 |
+
resp = api.send_message(text)
|
|
|
10 |
api.refresh_auth()
|
11 |
api.reset_conversation()
|
12 |
+
response = resp['message']
|
13 |
+
logger.info(f"response_: {response}")
|
14 |
except:
|
15 |
+
response = "Sorry, I'm am tired."
|
16 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
18 |
import gradio as gr
|
19 |
+
demo = gr.Interface(chat,
|
20 |
+
inputs = [gr.Textbox(label = 'Input: ')],
|
21 |
+
outputs = gr.outputs.Textbox(type="text",label="from ChatGPT:"),
|
22 |
+
title = "talk with ChatGPT",
|
23 |
+
description= "")
|
24 |
+
demo.launch(debug = True)
|