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