harrygens commited on
Commit
c066489
0 Parent(s):

Duplicate from harrygens/chatbot

Browse files
Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +50 -0
  4. requirements.txt +3 -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: Chatbot
3
+ emoji: 📚
4
+ colorFrom: gray
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.24.1
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: harrygens/chatbot
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import os
4
+ import logging
5
+ import json
6
+ #import uuid
7
+
8
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
9
+
10
+ openai.api_key = os.environ['key']
11
+
12
+ #session_id = str(uuid.uuid4())
13
+
14
+ #messages = [{"role": "system", "content": "Your name is Harry and you are an AI assistant who can answer any question except to clarify that you are an AI"},]
15
+
16
+ def chatbot(input, messages):
17
+ messages = messages or [{"role": "system", "content": "Your name is Harry and you are an AI assistant who can answer any question except to clarify that you are an AI!"}]
18
+ if input:
19
+ messages.append({"role": "user", "content": input})
20
+ chat = openai.ChatCompletion.create(
21
+ model="gpt-3.5-turbo", messages=messages,
22
+ max_tokens=2048,n=1,temperature=0.5,
23
+ )
24
+ reply = chat.choices[0].message.content
25
+ messages.append({"role": "assistant", "content": reply})
26
+ return reply, printMessages(messages), messages
27
+
28
+ def printMessages(messages):
29
+ delimiter = '\n'
30
+ msg_string = delimiter.join([f"{obj['role']}:{obj['content']}" for obj in messages[1:]])
31
+ logging.info("messages:"+msg_string)
32
+ return msg_string
33
+
34
+ #def clearMessage():
35
+ # global messages
36
+ # messages = [{"role": "system", "content": "Your name is Harry and you are an AI assistant who can answer any question except to clarify that you are an AI"},]
37
+ # logging.info("clear messages")
38
+
39
+ #with gr.Blocks() as app:
40
+ #newChatBtn = gr.Button("New Chat")
41
+ #newChatBtn.click(clearMessage)
42
+ #tbReply = gr.Textbox(label="Reply")
43
+ #tbHistroy = gr.Textbox(label="History Chat")
44
+ #inputs = [gr.Textbox(lines=7, label="Chat with Harry"), newChatBtn] #Hidden(label="Session ID", value=session_id)]
45
+ #outputs = [gr.Textbox(label="History Chat"), gr.Textbox(label="Reply")]
46
+
47
+ app = gr.Interface(fn=chatbot, inputs=[gr.Textbox(lines=7, label="Chat with Harry"), "state"],
48
+ outputs=[gr.Textbox(label="Reply"), gr.Textbox(label="History"), "state"], title="Chat with Harry",
49
+ description="Ask anything you want",theme="compact")
50
+ app.launch(share=False)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ openai
2
+ gradio
3
+ transformers