ThomasFfefefef commited on
Commit
867c9b3
1 Parent(s): e0e5a42

Added app.py and csv files

Browse files
Files changed (4) hide show
  1. app.py +120 -0
  2. charles.csv +26 -0
  3. eleanor.csv +26 -0
  4. tom.csv +26 -0
app.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import requests
4
+
5
+ import numpy as np
6
+
7
+ import pandas as pd
8
+
9
+
10
+ # Template
11
+ title = "Murder on Horsea Island Prototype 🔪 (WORK IN PROGRESS)"
12
+ description = "Prototype of the Unity Game (to test the questions)."
13
+ article = """
14
+ """
15
+ theme="huggingface"
16
+
17
+ # examples =
18
+
19
+ # API
20
+ API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/paraphrase-xlm-r-multilingual-v1"
21
+
22
+
23
+
24
+ # Build the 3 different questions array before starting
25
+ def build_initial_questions_and_answers():
26
+ # Eleanor
27
+ eleanor_df = pd.read_csv("eleanor.csv", delimiter=",")
28
+ eleanor_len = eleanor_df.shape[0]
29
+ eleanor_questions = [eleanor_df["Questions"][i] for i in range(eleanor_len)]
30
+ eleanor_answers = [eleanor_df["Answers"][i] for i in range(eleanor_len)]
31
+
32
+ # Tom
33
+ tom_df = pd.read_csv("tom.csv", delimiter=",")
34
+ tom_len = tom_df.shape[0]
35
+ tom_questions = [tom_df["Questions"][i] for i in range(tom_len)]
36
+ tom_answers = [tom_df["Answers"][i] for i in range(tom_len)]
37
+
38
+ # Charles
39
+ charles_df = pd.read_csv("charles.csv", delimiter=",")
40
+ charles_len = charles_df.shape[0]
41
+ charles_questions = [charles_df["Questions"][i] for i in range(charles_len)]
42
+ charles_answers = [charles_df["Answers"][i] for i in range(charles_len)]
43
+
44
+ return eleanor_questions, eleanor_answers, tom_questions, tom_answers, charles_questions, charles_answers
45
+
46
+
47
+
48
+ def build_json(message, questions):
49
+ json = {
50
+ "inputs": {
51
+ "source_sentence": message,
52
+ "sentences": questions
53
+ },
54
+ }
55
+ return json
56
+
57
+
58
+ def query(payload):
59
+ response = requests.post(API_URL, json=payload)
60
+ return response.json()
61
+
62
+ def answer(output_json, character):
63
+ # First we handle output_json
64
+ idx = np.argmax(output_json)
65
+
66
+ if (character == "eleanor"):
67
+ answer_ = eleanor_answers[idx]
68
+
69
+ elif (character == "tom"):
70
+ answer_ = tom_answers[idx]
71
+
72
+ else:
73
+ answer_ = charles_answers[idx]
74
+
75
+ return answer_
76
+
77
+
78
+ def chat(message, character):
79
+ history = gr.get_state() or []
80
+
81
+ if (character == "eleanor"):
82
+ json = build_json(message, eleanor_questions)
83
+
84
+ elif (character == "tom"):
85
+ json = build_json(message, tom_questions)
86
+
87
+ else:
88
+ json = build_json(message, charles_questions)
89
+
90
+ output = query(json)
91
+
92
+ answer_ = answer(output, character)
93
+
94
+
95
+ history.append((message, answer_))
96
+ gr.set_state(history)
97
+ html = ""
98
+ for user_msg, resp_msg in history:
99
+ html += f"{user_msg}"
100
+ html += f"{resp_msg}"
101
+ html += ""
102
+ return html
103
+
104
+ eleanor_questions, eleanor_answers, tom_questions, tom_answers, charles_questions, charles_answers = build_initial_questions_and_answers()
105
+
106
+ choices = ["Eleanor", "Tom", "Charles (The Butler)"]
107
+ character = gr.inputs.Radio(choices, type="value", default=None, label=None)
108
+
109
+ iface = gr.Interface(chat, ["text", character], "html", css="""
110
+ .chatbox {display:flex;flex-direction:column}
111
+ .user_msg, .resp_msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
112
+ .user_msg {background-color:cornflowerblue;color:white;align-self:start}
113
+ .resp_msg {background-color:lightgray;align-self:self-end}
114
+ """, allow_screenshot=False, allow_flagging=False)
115
+
116
+ iface.launch()
117
+
118
+ if __name__ == "__main__":
119
+
120
+ iface.launch()
charles.csv ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Questions,Answers
2
+ Who are you?,"I'm Lady Eleanor Kent, wife of Sir Edward Kent. But you know me, I'm the most famous actress of UK."
3
+ I'm sorry I don't know you were an actress,"You're kidding right! I was the best actress of UK 20 years ago, the most magnificient actress and the most beautiful one."
4
+ You were a good actress?,"I was the best, but now I'm not anymore, far from London on this dead island..."
5
+ Where were you?,"I was in my bedroom during the whole time, when I came down at 8:30PM nobody was in the dining room."
6
+ What you can tell me about Sir Edward,Sir Edward and me were married for 20 years. We met when I was an actress in London I played Lady MacBeth's role.
7
+ You don't seem really sad of the death of your husband,How dare you! I just lost my husband and you accuse me to not be sad enough! A lady must hide her emotions.
8
+ Does Sir Edward has enemies?,He was a tough businessman though I don't think he has any enemy
9
+ Do you think Sir Edward killed himself?,"Are you stupid? He was stabbed 6 times, do you really believe that he can kill himself like that? "
10
+ How do you know he was stabbed 6 times?,Well... Hum... I think it was one of the policeman who told me.
11
+ Do you know why someone killed Sir Edward,I don't know. That makes no sense.
12
+ What can you tell me about Charles the butler ?,"Charles is in our home since 20 years, he's a very good butler, very kind."
13
+ What can you tell me about Phyllis the maid ?,"Phyllis is my maid since 20 years, she was hired when I arrived on the island. She's very serviceable, though a little bit gauche sometimes."
14
+ "What can you tell me about Tom the lighthouse keeper, lightkeeper ?","Tom arrived one year ago, he's a very good lightkeeper. He loves Shakespear like me, I'm happy to have finally someone cultivé like me."
15
+ Tom knows Shakespeare,"Yes a little bit, but anyway that's not important, he's a good lightkeeper that's all that matters"
16
+ Do you think the buttler,t
17
+ You don't like this island?,"No, no ! I like this island but... I would love to go back to live in London"
18
+ Why you can't go back to London?,"Because Edward refused, he loves this island"
19
+ Why you killed Sir Edward?,How dare you! I just lost my husband and you accuse me!
20
+ I'm sure you're the killer,How dare you! I just lost my husband and you accuse me of stabbing him!
21
+ Fuck you,That's really rude! You insult a lady! I will tell your superior about that!
22
+ What where you doing during the murder,I was in my bedroom
23
+ Why you were in your bedroom?,Nothing special
24
+ You were in your bedroom because you had an argument with Sir Edward,"That is true, he refused against that I go to London to make career as an actress as before"
25
+ No you were in your bedroom because you said him you wanted to divorce and he refused again,How do you know about that?!
26
+ I read your journal,"That's impolite! But yes, I admit, I wanted to quit him, but not kill him for it!"
eleanor.csv ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Questions,Answers
2
+ Who are you?,"I'm Lady Eleanor Kent, wife of Sir Edward Kent. But you know me, I'm the most famous actress of UK."
3
+ I'm sorry I don't know you were an actress,"You're kidding right! I was the best actress of UK 20 years ago, the most magnificient actress and the most beautiful one."
4
+ You were a good actress?,"I was the best, but now I'm not anymore, far from London on this dead island..."
5
+ Where were you?,"I was in my bedroom during the whole time, when I came down at 8:30PM nobody was in the dining room."
6
+ What you can tell me about Sir Edward,Sir Edward and me were married for 20 years. We met when I was an actress in London I played Lady MacBeth's role.
7
+ You don't seem really sad of the death of your husband,How dare you! I just lost my husband and you accuse me to not be sad enough! A lady must hide her emotions.
8
+ Does Sir Edward has enemies?,He was a tough businessman though I don't think he has any enemy
9
+ Do you think Sir Edward killed himself?,"Are you stupid? He was stabbed 6 times, do you really believe that he can kill himself like that? "
10
+ How do you know he was stabbed 6 times?,Well... Hum... I think it was one of the policeman who told me.
11
+ Do you know why someone killed Sir Edward,I don't know. That makes no sense.
12
+ What can you tell me about Charles the butler ?,"Charles is in our home since 20 years, he's a very good butler, very kind."
13
+ What can you tell me about Phyllis the maid ?,"Phyllis is my maid since 20 years, she was hired when I arrived on the island. She's very serviceable, though a little bit gauche sometimes."
14
+ "What can you tell me about Tom the lighthouse keeper, lightkeeper ?","Tom arrived one year ago, he's a very good lightkeeper. He loves Shakespear like me, I'm happy to have finally someone cultivé like me."
15
+ Tom knows Shakespeare,"Yes a little bit, but anyway that's not important, he's a good lightkeeper that's all that matters"
16
+ Do you think the buttler,t
17
+ You don't like this island?,"No, no ! I like this island but... I would love to go back to live in London"
18
+ Why you can't go back to London?,"Because Edward refused, he loves this island"
19
+ Why you killed Sir Edward?,How dare you! I just lost my husband and you accuse me!
20
+ I'm sure you're the killer,How dare you! I just lost my husband and you accuse me of stabbing him!
21
+ Fuck you,That's really rude! You insult a lady! I will tell your superior about that!
22
+ What where you doing during the murder,I was in my bedroom
23
+ Why you were in your bedroom?,Nothing special
24
+ You were in your bedroom because you had an argument with Sir Edward,"That is true, he refused against that I go to London to make career as an actress as before"
25
+ No you were in your bedroom because you said him you wanted to divorce and he refused again,How do you know about that?!
26
+ I read your journal,"That's impolite! But yes, I admit, I wanted to quit him, but not kill him for it!"
tom.csv ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Questions,Answers
2
+ Who are you?,"I'm Lady Eleanor Kent, wife of Sir Edward Kent. But you know me, I'm the most famous actress of UK."
3
+ I'm sorry I don't know you were an actress,"You're kidding right! I was the best actress of UK 20 years ago, the most magnificient actress and the most beautiful one."
4
+ You were a good actress?,"I was the best, but now I'm not anymore, far from London on this dead island..."
5
+ Where were you?,"I was in my bedroom during the whole time, when I came down at 8:30PM nobody was in the dining room."
6
+ What you can tell me about Sir Edward,Sir Edward and me were married for 20 years. We met when I was an actress in London I played Lady MacBeth's role.
7
+ You don't seem really sad of the death of your husband,How dare you! I just lost my husband and you accuse me to not be sad enough! A lady must hide her emotions.
8
+ Does Sir Edward has enemies?,He was a tough businessman though I don't think he has any enemy
9
+ Do you think Sir Edward killed himself?,"Are you stupid? He was stabbed 6 times, do you really believe that he can kill himself like that? "
10
+ How do you know he was stabbed 6 times?,Well... Hum... I think it was one of the policeman who told me.
11
+ Do you know why someone killed Sir Edward,I don't know. That makes no sense.
12
+ What can you tell me about Charles the butler ?,"Charles is in our home since 20 years, he's a very good butler, very kind."
13
+ What can you tell me about Phyllis the maid ?,"Phyllis is my maid since 20 years, she was hired when I arrived on the island. She's very serviceable, though a little bit gauche sometimes."
14
+ "What can you tell me about Tom the lighthouse keeper, lightkeeper ?","Tom arrived one year ago, he's a very good lightkeeper. He loves Shakespear like me, I'm happy to have finally someone cultivé like me."
15
+ Tom knows Shakespeare,"Yes a little bit, but anyway that's not important, he's a good lightkeeper that's all that matters"
16
+ Do you think the buttler,t
17
+ You don't like this island?,"No, no ! I like this island but... I would love to go back to live in London"
18
+ Why you can't go back to London?,"Because Edward refused, he loves this island"
19
+ Why you killed Sir Edward?,How dare you! I just lost my husband and you accuse me!
20
+ I'm sure you're the killer,How dare you! I just lost my husband and you accuse me of stabbing him!
21
+ Fuck you,That's really rude! You insult a lady! I will tell your superior about that!
22
+ What where you doing during the murder,I was in my bedroom
23
+ Why you were in your bedroom?,Nothing special
24
+ You were in your bedroom because you had an argument with Sir Edward,"That is true, he refused against that I go to London to make career as an actress as before"
25
+ No you were in your bedroom because you said him you wanted to divorce and he refused again,How do you know about that?!
26
+ I read your journal,"That's impolite! But yes, I admit, I wanted to quit him, but not kill him for it!"