sunzijun commited on
Commit
a102655
β€’
1 Parent(s): 7b48c22

ADD: init repo

Browse files
Files changed (2) hide show
  1. app.py +53 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ @file : app.py
5
+ @author: sunzijun
6
+ @contact : sunzijun@pku.edu.cn
7
+ @date : 2022/12/7 1:08 上午
8
+ @version: 1.0
9
+ @desc :
10
+ """
11
+ import os
12
+
13
+ from pyChatGPT import ChatGPT
14
+
15
+
16
+ def chat_hf(text, session_tokenz):
17
+ try:
18
+ # Save the session_token variable to the system environment
19
+ os.environ['SESSION_TOKEN'] = session_token
20
+
21
+ # Load the saved session_token value from the system environment
22
+ loaded_session_token = os.environ['SESSION_TOKEN']
23
+
24
+ api = ChatGPT(session_token)
25
+ resp = api.send_message(text)
26
+
27
+ api.refresh_auth() # refresh the authorization token
28
+ api.reset_conversation() # reset the conversation
29
+ xyz = resp['message']
30
+ except:
31
+
32
+ api = ChatGPT(session_tokenz)
33
+ resp = api.send_message(text)
34
+
35
+ api.refresh_auth() # refresh the authorization token
36
+ api.reset_conversation() # reset the conversation
37
+ xyz = resp['message']
38
+
39
+ return xyz
40
+
41
+
42
+ # @title GRadio for SDK api
43
+
44
+ import gradio as gr
45
+
46
+ gr.Interface(
47
+ chat_hf,
48
+ [gr.Textbox(label=' Input '),
49
+ gr.Textbox(label=' If it fails enter cusom session ')],
50
+ outputs=gr.outputs.Textbox(type="text", label="chatGPT response")
51
+ , title="" + ' ChatGpt πŸ€–πŸ’¬πŸ’» on hugginface. ' + "",
52
+ description="ChatGPT is a powerful dialog model trained by OpenAI").launch(
53
+ debug=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ pyChatGPT