thelou1s SourcezZ commited on
Commit
8680b3c
0 Parent(s):

Duplicate from SourcezZ/chat_gpt_space

Browse files

Co-authored-by: source <SourcezZ@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +44 -0
  4. requirements.txt +0 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Chat Gpt Space
3
+ emoji: 📚
4
+ colorFrom: purple
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 3.20.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: SourcezZ/chat_gpt_space
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import openai
3
+ import os
4
+
5
+ openai.api_key = os.environ["API_KEY"] # 首先要有apikey
6
+ messages = [{"role": "system", "content": "你是一个得力助手"}]
7
+
8
+
9
+ def chatgpt(content, temperature=0.8):
10
+ global messages
11
+ print(f'ask:{content}')
12
+ messages.append({"role": "user", "content": content})
13
+ try:
14
+ response = openai.ChatCompletion.create(
15
+ model="gpt-3.5-turbo-0301", # 或者 gpt-3.5-turbo-0301
16
+ messages=messages,
17
+ temperature=temperature,
18
+ max_tokens=1000,
19
+ top_p=1,
20
+ frequency_penalty=0,
21
+ presence_penalty=0,
22
+ )
23
+ except Exception as e:
24
+ messages = [{"role": "system", "content": "你是一个得力助手"}]
25
+ return '本次互动消息已达上限,已清空Token,请重新输入'
26
+ messages.append(json.loads(str(response.choices[0].message)))
27
+ print(f'answer:{response.choices[0].message.content}')
28
+ return response.choices[0].message.content
29
+
30
+
31
+ if __name__ == "__main__":
32
+ import gradio as gr
33
+
34
+
35
+ def send_chatgpt(text):
36
+ output = chatgpt(text, 0.8)
37
+ return output
38
+
39
+
40
+ input_text = gr.inputs.Textbox(label="输入问题:")
41
+ output_text = gr.outputs.Textbox(label="回答:")
42
+ interface = gr.Interface(fn=send_chatgpt, inputs=input_text, outputs=output_text, title="ChatGPT问答")
43
+ # interface.launch(share=True)
44
+ interface.launch()
requirements.txt ADDED
Binary file (30 Bytes). View file