giannicrivello commited on
Commit
ffb5b36
1 Parent(s): 26bd2a3

test chat bot

Browse files
Files changed (2) hide show
  1. app.py +32 -20
  2. test/app.py +0 -37
app.py CHANGED
@@ -1,25 +1,37 @@
1
  import gradio as gr
 
 
2
 
 
 
 
 
3
 
4
- examples = []
 
 
 
5
 
6
- def yes_man(message, history):
7
- if message.endswith("?"):
8
- examples.append(message)
9
- return "Yes"
10
- else:
11
- return "Ask me anything!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- gr.ChatInterface(
14
- yes_man,
15
- chatbot=gr.Chatbot(height=500),
16
- textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
17
- title="Yes Man",
18
- description="Ask Yes Man any question",
19
- theme="soft",
20
- examples=examples,
21
- cache_examples=True,
22
- retry_btn=None,
23
- undo_btn="Delete Previous",
24
- clear_btn="Clear",
25
- ).launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+ from transformers import Conversation
4
 
5
+ pipe = pipeline("conversational", model="PygmalionAI/pygmalion-6b")
6
+ conversation = Conversation()
7
+ conversation.add_message({"role": "assistant", "content": "How can I help you?"})
8
+ memory = []
9
 
10
+ def run_conversation(message, history):
11
+ #cache memory from user
12
+ memory.append({"role": "user", "content": message})
13
+ print(history)
14
 
15
+ if len(history) > 0:
16
+ for i in history:
17
+ conversation.add_message({"role":"user", "content":i[0]})
18
+ conversation.add_message({"role": "assistant", "content": i[1]})
19
+ for i in memory:
20
+ conversation.add_message(i)
21
+ print(conversation)
22
+
23
+ pipe(conversation)
24
+ return conversation.generated_responses[-1]
25
+
26
+ demo = gr.ChatInterface(
27
+ run_conversation,
28
+ chatbot = gr.Chatbot(height=500),
29
+ textbox = gr.Textbox(placeholder="Chat with me!", scale=7),
30
+ title = "Test",
31
+ description="Chat with me!"
32
+ examples=["hello"]
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ demo.queue().launch()
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test/app.py DELETED
@@ -1,37 +0,0 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
- from transformers import Conversation
4
-
5
- pipe = pipeline("conversational", model="PygmalionAI/pygmalion-6b")
6
- conversation = Conversation()
7
- conversation.add_message({"role": "assistant", "content": "How can I help you?"})
8
- memory = []
9
-
10
- def run_conversation(message, history):
11
- #cache memory from user
12
- memory.append({"role": "user", "content": message})
13
- print(history)
14
-
15
- if len(history) > 0:
16
- for i in history:
17
- conversation.add_message({"role":"user", "content":i[0]})
18
- conversation.add_message({"role": "assistant", "content": i[1]})
19
- for i in memory:
20
- conversation.add_message(i)
21
- print(conversation)
22
-
23
- pipe(conversation)
24
- return conversation.generated_responses[-1]
25
-
26
- demo = gr.ChatInterface(
27
- run_conversation,
28
- chatbot = gr.Chatbot(height=500),
29
- textbox = gr.Textbox(placeholder="Chat with me!", scale=7),
30
- title = "Test",
31
- description="Chat with me!"
32
- examples=["hello"]
33
- )
34
-
35
- if __name__ == "__main__":
36
- demo.queue().launch()
37
-