iamstrong commited on
Commit
0522ba8
·
verified ·
1 Parent(s): d7faaaf

Upload 3 files

Browse files
Files changed (1) hide show
  1. app.py +49 -53
app.py CHANGED
@@ -1,8 +1,8 @@
1
-
2
  from gtts import gTTS
3
  import tempfile
4
  import json
5
  import datetime
 
6
 
7
  # User data
8
  user_info = {"name": "", "age": "", "gender": "", "language": "english"}
@@ -34,47 +34,47 @@ lang_codes = {
34
  # List of harmful or dangerous keywords
35
  harmful_keywords = [
36
  "suicide", "kill myself", "end my life", "harm myself", "cut myself",
37
- "want to die", "die", "jump off", "self-harm", "give up", "not worth it", "ending it all","abomination", "abysmal", "agony", "alcohol", "alien", "anger", "angsty", "annihilate", "anti", "arson",
38
- "ass", "assault", "atrocity", "awful", "backstab", "backstabber", "barbaric", "barbarian", "beast", "belittle",
39
- "berserk", "betray", "betrayal", "bigot", "bigoted", "bitter", "blacklist", "blasphemy", "blind", "blockhead",
40
- "blood", "bloodbath", "bloody", "blunder", "boastful", "bogus", "bomb", "bonehead", "brainless", "brutal",
41
- "brute", "brutality", "burn", "butcher", "cage", "caged", "callous", "cancer", "careless", "chaos",
42
- "cheap", "cheater", "childish", "clueless", "coarse", "cold-blooded", "con", "conman", "contempt", "contradict",
43
- "corrupt", "cowardly", "crash", "craze", "crazed", "creepy", "crime", "criminality", "crook", "cruel",
44
- "cruelty", "crybaby", "curseword", "cynical", "damage", "damaging", "danger", "dangerous", "dark", "deadly",
45
- "deceit", "deceitful", "deceive", "deceiver", "deceptive", "defame", "defeat", "defeated", "defiance", "defiant",
46
- "degenerate", "demented", "demon", "despise", "destroy", "destruction", "destructive", "devastate", "devil", "diabolical",
47
- "dictator", "die", "dirty", "disaster", "disgust", "disgusted", "dishonor", "dishonest", "disloyal", "dismiss",
48
- "disrespect", "disturb", "divisive", "doom", "doomed", "dread", "dreadful", "drunk", "drunkard", "dumbass",
49
- "dungeon", "egotistical", "enemies", "enemy", "enrage", "evilness", "exile", "exploit", "exterminate", "fake",
50
- "fakeness", "fallen", "fanatic", "fascist", "fatal", "filthy", "fire", "flawed", "foolish", "forbid",
51
- "forceful", "forgery", "foul", "fraud", "fraudster", "freakish", "frighten", "frightful", "gang", "gangster",
52
- "ghastly", "ghost", "ghoul", "gloom", "gory", "grief", "gross", "grotesque", "gruesome", "grumpy",
53
- "guilty", "hag", "halfwit", "hardhearted", "harm", "harsh", "hateable", "hateful", "havoc", "hell",
54
- "hellish", "heretic", "hideous", "horrid", "horrific", "hostility", "howl", "hurt", "hypocrite", "hypocrisy",
55
- "idiotic", "idiocy", "ignoramus", "ill", "illegal", "illicit", "immature", "immoral", "imposter", "incapable",
56
- "incompetent", "indecent", "indifference", "indifferent", "infect", "inferior", "infuriate", "inhuman", "inhumane", "injure",
57
- "insensitive", "insidious", "insolent", "intolerant", "irate", "irritate", "irritating", "jerky", "joke", "joker",
58
- "kidnap", "killjoy", "knock", "lawless", "liability", "lie", "loath", "loathsome", "lowlife", "madness",
59
- "malicious", "malign", "manipulate", "menace", "mess", "messy", "miser", "mock", "mocking", "monster",
60
- "monstrous", "moody", "mug", "murderous", "mutant", "mutiny", "nag", "nasty", "nefarious", "neglect",
61
- "negative", "nemesis", "nonsense", "nosy", "obnoxious", "offend", "offender", "ominous", "oppress", "outrage",
62
- "outrageous", "pain", "painful", "parasite", "pariah", "partisan", "peculiar", "penalty", "perish", "pest",
63
- "petrify", "pitiful", "plague", "poison", "poisonous", "pollute", "poverty", "prejudice", "pretend", "problem",
64
- "psychopath", "punch", "punish", "punishment", "quarrel", "quitter", "rage", "ragged", "rat", "rebellion",
65
- "reckless", "rejects", "repel", "repulsive", "revolt", "revolting", "rioter", "rob", "robber", "rotten",
66
- "rough", "ruin", "ruined", "rupture", "savage", "scar", "scare", "scared", "scary", "schemer",
67
- "scold", "scorn", "scoundrel", "scream", "screwed", "self-hate", "selfishness", "serpent", "shady", "sham",
68
- "shameful", "shatter", "shocking", "silly", "sin", "sinister", "skeptic", "slavey", "slimy", "slum",
69
- "smash", "smelly", "smite", "snob", "snobbish", "snub", "sob", "sorrow", "spite", "spiteful",
70
- "stab", "stench", "stink", "storm", "stress", "stressed", "strike", "struggle", "stubborn", "subvert",
71
- "suicidal", "suspicious", "taint", "tantrum", "target", "tease", "terrible", "terrify", "thief", "threat",
72
- "threaten", "thug", "torment", "torture", "tragic", "trap", "trauma", "trick", "trigger", "trouble",
73
- "troubling", "ugliness", "uncivilized", "undermine", "unfair", "unhappy", "unjust", "unkind", "unlucky", "unpleasant",
74
- "unworthy", "upset", "usurper", "vandal", "vandalize", "venom", "venomous", "villain", "villainous", "vindictive",
75
- "violent", "viper", "vulgarity", "war", "warmonger", "waste", "wasteful", "wickedness", "wild", "wound",
76
- "wrath", "wreck", "wrong", "yell", "yucky", "zero", "zombie"
77
-
78
  ]
79
 
80
  # Harmful word detection response
@@ -94,7 +94,7 @@ harmful_response = (
94
 
95
  # Simplified emotions dictionary
96
  emotions = {
97
- "sad": "It’s okay to feel sad. Let yourself cry if you need to. I’m here for you.",
98
  "anxiety": "Try a calming breath: in for 4, hold for 4, out for 4. You’ve got this.",
99
  "angry": "Take a deep breath. Let’s find a peaceful way to express your feelings.",
100
  "lonely": "You are not alone. Talking helps — I’m here to listen.",
@@ -341,17 +341,15 @@ emotions = {
341
 
342
  }
343
 
344
- # Save personal information
345
  def set_personal_info(name, age, gender, language):
346
  user_info.update({"name": name, "age": age, "gender": gender, "language": language})
347
  return gr.update(visible=True), f"✅ Welcome {name}! Preferences saved."
348
 
349
- # Display user info
350
  def show_personal_data():
351
  today = datetime.date.today().strftime("%Y-%m-%d (%A)")
352
  return f"📅 {today}\n👤 Name: {user_info['name']}\n🎂 Age: {user_info['age']}\n♀ Gender: {user_info['gender']}\n🌐 Language: {user_info['language']}"
353
 
354
- # Detect emotion or harmful input
355
  def generate_reply(input_text):
356
  text = input_text.lower()
357
  for word in harmful_keywords:
@@ -362,20 +360,16 @@ def generate_reply(input_text):
362
  return reply
363
  return "Tell me more about your day."
364
 
365
- # Chat logic
366
  def chat_function(audio_input, text_input):
367
  user_text = text_input.strip()
368
  if not user_text:
369
  return "Please type something.", None
370
-
371
  reply = generate_reply(user_text)
372
  chat_history.append({"user": user_text, "bot": reply})
373
-
374
  lang_code = lang_codes.get(user_info["language"], "en")
375
  tts = gTTS(reply, lang=lang_code)
376
  audio_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
377
  tts.save(audio_file.name)
378
-
379
  return reply, audio_file.name
380
 
381
  def get_chat_history():
@@ -402,8 +396,8 @@ def next_study_tip():
402
  tip_index["study"] += 1
403
  return tip
404
 
405
-
406
-
407
  welcome_screen = gr.Column(visible=True)
408
  full_app = gr.Tabs(visible=False)
409
 
@@ -483,4 +477,6 @@ def next_study_tip():
483
  </iframe>
484
  '''
485
  )
486
- app.launch()
 
 
 
 
1
  from gtts import gTTS
2
  import tempfile
3
  import json
4
  import datetime
5
+ import gradio as gr
6
 
7
  # User data
8
  user_info = {"name": "", "age": "", "gender": "", "language": "english"}
 
34
  # List of harmful or dangerous keywords
35
  harmful_keywords = [
36
  "suicide", "kill myself", "end my life", "harm myself", "cut myself",
37
+ "want to die", "die", "jump off", "self-harm", "give up", "not worth it", "ending it all",
38
+ "abomination", "abysmal", "agony", "alcohol", "alien", "anger", "angsty", "annihilate", "anti", "arson",
39
+ "ass", "assault", "atrocity", "awful", "backstab", "backstabber", "barbaric", "barbarian", "beast", "belittle",
40
+ "berserk", "betray", "betrayal", "bigot", "bigoted", "bitter", "blacklist", "blasphemy", "blind", "blockhead",
41
+ "blood", "bloodbath", "bloody", "blunder", "boastful", "bogus", "bomb", "bonehead", "brainless", "brutal",
42
+ "brute", "brutality", "burn", "butcher", "cage", "caged", "callous", "cancer", "careless", "chaos",
43
+ "cheap", "cheater", "childish", "clueless", "coarse", "cold-blooded", "con", "conman", "contempt", "contradict",
44
+ "corrupt", "cowardly", "crash", "craze", "crazed", "creepy", "crime", "criminality", "crook", "cruel",
45
+ "cruelty", "crybaby", "curseword", "cynical", "damage", "damaging", "danger", "dangerous", "dark", "deadly",
46
+ "deceit", "deceitful", "deceive", "deceiver", "deceptive", "defame", "defeat", "defeated", "defiance", "defiant",
47
+ "degenerate", "demented", "demon", "despise", "destroy", "destruction", "destructive", "devastate", "devil", "diabolical",
48
+ "dictator", "die", "dirty", "disaster", "disgust", "disgusted", "dishonor", "dishonest", "disloyal", "dismiss",
49
+ "disrespect", "disturb", "divisive", "doom", "doomed", "dread", "dreadful", "drunk", "drunkard", "dumbass",
50
+ "dungeon", "egotistical", "enemies", "enemy", "enrage", "evilness", "exile", "exploit", "exterminate", "fake",
51
+ "fakeness", "fallen", "fanatic", "fascist", "fatal", "filthy", "fire", "flawed", "foolish", "forbid",
52
+ "forceful", "forgery", "foul", "fraud", "fraudster", "freakish", "frighten", "frightful", "gang", "gangster",
53
+ "ghastly", "ghost", "ghoul", "gloom", "gory", "grief", "gross", "grotesque", "gruesome", "grumpy",
54
+ "guilty", "hag", "halfwit", "hardhearted", "harm", "harsh", "hateable", "hateful", "havoc", "hell",
55
+ "hellish", "heretic", "hideous", "horrid", "horrific", "hostility", "howl", "hurt", "hypocrite", "hypocrisy",
56
+ "idiotic", "idiocy", "ignoramus", "ill", "illegal", "illicit", "immature", "immoral", "imposter", "incapable",
57
+ "incompetent", "indecent", "indifference", "indifferent", "infect", "inferior", "infuriate", "inhuman", "inhumane", "injure",
58
+ "insensitive", "insidious", "insolent", "intolerant", "irate", "irritate", "irritating", "jerky", "joke", "joker",
59
+ "kidnap", "killjoy", "knock", "lawless", "liability", "lie", "loath", "loathsome", "lowlife", "madness",
60
+ "malicious", "malign", "manipulate", "menace", "mess", "messy", "miser", "mock", "mocking", "monster",
61
+ "monstrous", "moody", "mug", "murderous", "mutant", "mutiny", "nag", "nasty", "nefarious", "neglect",
62
+ "negative", "nemesis", "nonsense", "nosy", "obnoxious", "offend", "offender", "ominous", "oppress", "outrage",
63
+ "outrageous", "pain", "painful", "parasite", "pariah", "partisan", "peculiar", "penalty", "perish", "pest",
64
+ "petrify", "pitiful", "plague", "poison", "poisonous", "pollute", "poverty", "prejudice", "pretend", "problem",
65
+ "psychopath", "punch", "punish", "punishment", "quarrel", "quitter", "rage", "ragged", "rat", "rebellion",
66
+ "reckless", "rejects", "repel", "repulsive", "revolt", "revolting", "rioter", "rob", "robber", "rotten",
67
+ "rough", "ruin", "ruined", "rupture", "savage", "scar", "scare", "scared", "scary", "schemer",
68
+ "scold", "scorn", "scoundrel", "scream", "screwed", "self-hate", "selfishness", "serpent", "shady", "sham",
69
+ "shameful", "shatter", "shocking", "silly", "sin", "sinister", "skeptic", "slavey", "slimy", "slum",
70
+ "smash", "smelly", "smite", "snob", "snobbish", "snub", "sob", "sorrow", "spite", "spiteful",
71
+ "stab", "stench", "stink", "storm", "stress", "stressed", "strike", "struggle", "stubborn", "subvert",
72
+ "suicidal", "suspicious", "taint", "tantrum", "target", "tease", "terrible", "terrify", "thief", "threat",
73
+ "threaten", "thug", "torment", "torture", "tragic", "trap", "trauma", "trick", "trigger", "trouble",
74
+ "troubling", "ugliness", "uncivilized", "undermine", "unfair", "unhappy", "unjust", "unkind", "unlucky", "unpleasant",
75
+ "unworthy", "upset", "usurper", "vandal", "vandalize", "venom", "venomous", "villain", "villainous", "vindictive",
76
+ "violent", "viper", "vulgarity", "war", "warmonger", "waste", "wasteful", "wickedness", "wild", "wound",
77
+ "wrath", "wreck", "wrong", "yell", "yucky", "zero", "zombie"
78
  ]
79
 
80
  # Harmful word detection response
 
94
 
95
  # Simplified emotions dictionary
96
  emotions = {
97
+ "sad": "It’s okay to feel sad. Let yourself cry if you need to. I’m here for you.",
98
  "anxiety": "Try a calming breath: in for 4, hold for 4, out for 4. You’ve got this.",
99
  "angry": "Take a deep breath. Let’s find a peaceful way to express your feelings.",
100
  "lonely": "You are not alone. Talking helps — I’m here to listen.",
 
341
 
342
  }
343
 
344
+ # Functions
345
  def set_personal_info(name, age, gender, language):
346
  user_info.update({"name": name, "age": age, "gender": gender, "language": language})
347
  return gr.update(visible=True), f"✅ Welcome {name}! Preferences saved."
348
 
 
349
  def show_personal_data():
350
  today = datetime.date.today().strftime("%Y-%m-%d (%A)")
351
  return f"📅 {today}\n👤 Name: {user_info['name']}\n🎂 Age: {user_info['age']}\n♀ Gender: {user_info['gender']}\n🌐 Language: {user_info['language']}"
352
 
 
353
  def generate_reply(input_text):
354
  text = input_text.lower()
355
  for word in harmful_keywords:
 
360
  return reply
361
  return "Tell me more about your day."
362
 
 
363
  def chat_function(audio_input, text_input):
364
  user_text = text_input.strip()
365
  if not user_text:
366
  return "Please type something.", None
 
367
  reply = generate_reply(user_text)
368
  chat_history.append({"user": user_text, "bot": reply})
 
369
  lang_code = lang_codes.get(user_info["language"], "en")
370
  tts = gTTS(reply, lang=lang_code)
371
  audio_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
372
  tts.save(audio_file.name)
 
373
  return reply, audio_file.name
374
 
375
  def get_chat_history():
 
396
  tip_index["study"] += 1
397
  return tip
398
 
399
+ # -------------- Gradio App --------------
400
+ with gr.Blocks() as app:
401
  welcome_screen = gr.Column(visible=True)
402
  full_app = gr.Tabs(visible=False)
403
 
 
477
  </iframe>
478
  '''
479
  )
480
+
481
+ if __name__ == "__main__":
482
+ app.launch()