Spaces:
Runtime error
Runtime error
Charanjeev2k2
commited on
Commit
·
68c590d
1
Parent(s):
99803c4
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import joblib
|
2 |
+
import os
|
3 |
+
import os.path
|
4 |
+
from os import path
|
5 |
+
import discord
|
6 |
+
import pandas as pd
|
7 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
8 |
+
from transformers import pipeline
|
9 |
+
from discord.ext import commands
|
10 |
+
from discord.ext import commands
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
positive = ['admiration', 'surprise','curiosity','desire','amusement', 'approval', 'caring', 'excitement','gratitude','joy', 'love', 'optimism', 'pride', 'relief']
|
15 |
+
negative = ['anger', 'annoyance', 'confusion','disappointment', 'disapproval', 'disgust', 'embarrassment', 'fear', 'grief', 'nervousness', 'realization', 'remorse', 'sadness']
|
16 |
+
emotions=["admiration", "amusement", "anger", "annoyance", "approval", "caring", "confusion", "curiosity", "desire", "disappointment", "disapproval", "disgust", "embarrassment", "excitement", "fear", "gratitude", "grief", "joy", "love", "nervousness", "optimism", "pride", "realization", "relief", "remorse", "sadness", "surprise"]
|
17 |
+
admiration_list=[]
|
18 |
+
admiration_idx=0
|
19 |
+
admiration_val=0
|
20 |
+
amusement_list=[]
|
21 |
+
amusement_idx=0
|
22 |
+
amusement_val=0
|
23 |
+
anger_list=[]
|
24 |
+
anger_idx=0
|
25 |
+
anger_val=0
|
26 |
+
annoyance_list=[]
|
27 |
+
annoyance_idx=0
|
28 |
+
annoyance_val=0
|
29 |
+
approval_list=[]
|
30 |
+
approval_idx=0
|
31 |
+
approval_val=0
|
32 |
+
caring_list=[]
|
33 |
+
caring_idx=0
|
34 |
+
caring_val=0
|
35 |
+
confusion_list=[]
|
36 |
+
confusion_idx=0
|
37 |
+
confusion_val=0
|
38 |
+
curiosity_list=[]
|
39 |
+
curiosity_idx=0
|
40 |
+
curiosity_val=0
|
41 |
+
desire_list=[]
|
42 |
+
desire_idx=0
|
43 |
+
desire_val=0
|
44 |
+
disappointment_list=[]
|
45 |
+
disappointment_idx=0
|
46 |
+
disappointment_val=0
|
47 |
+
disapproval_list=[]
|
48 |
+
disapproval_idx=0
|
49 |
+
disapproval_val=0
|
50 |
+
disgust_list=[]
|
51 |
+
disgust_idx=0
|
52 |
+
disgust_val=0
|
53 |
+
embarrassment_list=[]
|
54 |
+
embarrassment_idx=0
|
55 |
+
embrassment_val=0
|
56 |
+
excitement_list=[]
|
57 |
+
excitement_idx=0
|
58 |
+
excitement_val=0
|
59 |
+
fear_list=[]
|
60 |
+
fear_idx=0
|
61 |
+
fear_val=0
|
62 |
+
gratitude_list=[]
|
63 |
+
gratitude_idx=0
|
64 |
+
gratitude_val=0
|
65 |
+
grief_list=[]
|
66 |
+
grief_idx=0
|
67 |
+
grief_val=0
|
68 |
+
joy_list=[]
|
69 |
+
joy_idx=0
|
70 |
+
joy_val=0
|
71 |
+
love_list=[]
|
72 |
+
love_idx=0
|
73 |
+
love_val=0
|
74 |
+
nervousness_list=[]
|
75 |
+
nervousness_idx=0
|
76 |
+
nervousness_val=0
|
77 |
+
optimism_list=[]
|
78 |
+
optimism_idx=0
|
79 |
+
optimism_val=0
|
80 |
+
pride_list=[]
|
81 |
+
pride_idx=0
|
82 |
+
pride_val=0
|
83 |
+
realization_list=[]
|
84 |
+
realization_idx=0
|
85 |
+
realization_val=0
|
86 |
+
relief_list=[]
|
87 |
+
relief_idx=0
|
88 |
+
relief_val=0
|
89 |
+
remorse_list=[]
|
90 |
+
remorse_idx=0
|
91 |
+
remorse_val=0
|
92 |
+
sadness_list=[]
|
93 |
+
sadness_idx=0
|
94 |
+
sadness_val=0
|
95 |
+
surprise_list=[]
|
96 |
+
surprise_idx=0
|
97 |
+
surprise_val=0
|
98 |
+
neutral_list=[]
|
99 |
+
neutral_idx=0
|
100 |
+
neutral_val=0
|
101 |
+
basepath="/content/drive/MyDrive/raahee_activity_recommendations/"
|
102 |
+
t=0
|
103 |
+
for emotion in emotions:
|
104 |
+
filepath=basepath+emotion
|
105 |
+
responsepath=filepath+"_responses.xlsx"
|
106 |
+
if(os.path.exists(responsepath)):
|
107 |
+
df=pd.read_excel(responsepath)
|
108 |
+
emotion+="_list"
|
109 |
+
for i in df['Unnamed: 0']:
|
110 |
+
globals()[emotion].append(i)
|
111 |
+
|
112 |
+
else:
|
113 |
+
gifpath=filepath+"_gifs.xlsx"
|
114 |
+
if(os.path.exists(gifpath)):
|
115 |
+
df=pd.read_excel(gifpath)
|
116 |
+
emotion+="_list"
|
117 |
+
for i in df['Unnamed: 0']:
|
118 |
+
globals()[emotion].append(i)
|
119 |
+
|
120 |
+
else:
|
121 |
+
moviepath=filepath+"_movies.xlsx"
|
122 |
+
if(os.path.exists(moviepath)):
|
123 |
+
df=pd.read_excel(moviepath)
|
124 |
+
emotion+="_list"
|
125 |
+
val=emotion
|
126 |
+
val+="_val"
|
127 |
+
globals()[val]=1
|
128 |
+
t=1
|
129 |
+
for i in df['Unnamed: 0']:
|
130 |
+
globals()[emotion].append(i)
|
131 |
+
else:
|
132 |
+
bookpath=filepath+"_books.xlsx"
|
133 |
+
t=2
|
134 |
+
val=emotion
|
135 |
+
val+="_val"
|
136 |
+
globals()[val]=2
|
137 |
+
if(os.path.exists(bookpath)):
|
138 |
+
df=pd.read_excel(bookpath)
|
139 |
+
emotion+="_list"
|
140 |
+
for i in df['Unnamed: 0']:
|
141 |
+
globals()[emotion].append(i)
|
142 |
+
|
143 |
+
|
144 |
+
client = discord.Client()
|
145 |
+
bot = commands.Bot(command_prefix='!')
|
146 |
+
|
147 |
+
|
148 |
+
|
149 |
+
#classifier = pipeline("text-classification",model='bhadresh-savani/bert-base-go-emotion')
|
150 |
+
|
151 |
+
|
152 |
+
def getEmotion(message):
|
153 |
+
return classifier(message)[0]["label"]
|
154 |
+
|
155 |
+
@client.event
|
156 |
+
async def on_ready():
|
157 |
+
print('We have logged in as {0.user}'.format(client))
|
158 |
+
|
159 |
+
@client.event
|
160 |
+
async def on_message(message):
|
161 |
+
if message.author == client.user:
|
162 |
+
return
|
163 |
+
if message.content.startswith('$hello'):
|
164 |
+
await message.channel.send('Hello!')
|
165 |
+
elif message.content.startswith('!pm'):
|
166 |
+
await message.channel.send('')
|
167 |
+
|
168 |
+
else:
|
169 |
+
print(message.author)
|
170 |
+
t=0
|
171 |
+
msg = message.content
|
172 |
+
|
173 |
+
print(msg)
|
174 |
+
response = getEmotion(msg)
|
175 |
+
print(response)
|
176 |
+
ans=""
|
177 |
+
greeting=""
|
178 |
+
val=response+"_list"
|
179 |
+
idx=response+"_idx"
|
180 |
+
temp=response+"_val"
|
181 |
+
print(idx)
|
182 |
+
print(temp)
|
183 |
+
print(globals()[temp])
|
184 |
+
if response in positive:
|
185 |
+
greeting = "Great to hear that <@{0.author.id}> !!!\n".format(message)
|
186 |
+
elif response in negative:
|
187 |
+
greeting = "<@{0.author.id}> I can completely understand what you're going through\n".format(message)
|
188 |
+
if(globals()[temp]==1):
|
189 |
+
greeting+="This movie made my day, hope it turns out the same for you too !\n"
|
190 |
+
if(globals()[temp]==2):
|
191 |
+
greeting+="I really enjoyed reading this book, I guess you must read it too!\n"
|
192 |
+
t=0
|
193 |
+
if(globals()[idx]<len(globals()[val])):
|
194 |
+
ans=globals()[val][globals()[idx]]
|
195 |
+
globals()[idx]+=1
|
196 |
+
else:
|
197 |
+
globals()[idx]=0
|
198 |
+
if(len(globals()[val])!=0):
|
199 |
+
ans=globals()[val][0]
|
200 |
+
globals()[idx]+=1
|
201 |
+
|
202 |
+
await message.channel.send(greeting+ans)
|
203 |
+
|
204 |
+
client.run(os.getenv("TOKEN"))
|