Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -57,6 +57,11 @@ class Pluto_Happy(object):
|
|
57 |
self._ph()
|
58 |
#
|
59 |
# define class var for stable division
|
|
|
|
|
|
|
|
|
|
|
60 |
#
|
61 |
self.fname_id = 0
|
62 |
self.dname_img = "img_colab/"
|
@@ -803,47 +808,23 @@ def add_method(cls):
|
|
803 |
return decorator
|
804 |
#
|
805 |
# [END OF pluto_happy]
|
806 |
-
## %%write app.py
|
807 |
-
|
808 |
-
import gradio
|
809 |
-
# %%write -a app.py
|
810 |
-
|
811 |
-
# wake up monty
|
812 |
-
monty = Pluto_Happy('Monty, shares or steal')
|
813 |
-
# %%write -a app.py
|
814 |
-
|
815 |
-
# check out my environments
|
816 |
-
|
817 |
-
# monty.fname_requirements = 'pluto_happy/requirements.txt'
|
818 |
-
# monty.print_info_self()
|
819 |
-
# %%write -a app.py
|
820 |
-
|
821 |
-
monty._huggingface_key=b'gAAAAABld_3fKLl7aPBJzfAq-th37t95pMu2bVbH9QccOSecaUnm33XrpKpCXP4GL6Wr23g3vtrKWli5JK1ZPh18ilnDb_Su6GoVvU92Vzba64k3gBQwKF_g5DoH2vWq2XM8vx_5mKJh'
|
822 |
-
monty._kaggle_key=b'gAAAAABld_4_B6rrRhFYyfl77dacu1RhR4ktaLU6heYhQBSIj4ELBm7y4DzU1R8-H4yPKd0w08s11wkFJ9AR7XyESxM1SsrMBzqQEeW9JKNbl6jAaonFGmqbhFblkQqH4XjsapZru0qX'
|
823 |
-
monty._fkey="fes_f8Im569hYnI1Tn6FqP-6hS4rdmNOJ6DWcRPOsvc="
|
824 |
-
monty._fkey=monty._fkey[::-1]
|
825 |
-
monty._ok=b'gAAAAABld_-y70otUll4Jwq3jEBXiw1tooSFo_gStRbkCyuu9_Dmdehc4M8lI_hFbum9CwyZuj9ZnXgxFIROebcPSF5qoA197VRvzUDQOMxY5zmHnImVROrsXVdZqXyIeYH_Q6cvXvFTX3rLBIKKWgvJmnpYGRaV6Q=='
|
826 |
-
|
827 |
-
# %%write -a app.py
|
828 |
|
829 |
-
|
830 |
-
ai_client = openai.OpenAI(api_key=monty.decrypt_it(monty._ok))
|
831 |
-
# %%write -a app.py
|
832 |
-
|
833 |
-
fname = 'toxic_data.csv'
|
834 |
-
monty.df_toxic_data = pandas.read_csv(fname)
|
835 |
# %%writefile -a app.py
|
836 |
-
#
|
837 |
-
|
|
|
838 |
@add_method(Pluto_Happy)
|
839 |
-
#
|
840 |
def _fetch_moderate_engine(self):
|
841 |
-
self.ai_client = openai.OpenAI(api_key=self.
|
842 |
self.text_model = "text-moderation-latest"
|
843 |
return
|
844 |
#
|
845 |
@add_method(Pluto_Happy)
|
846 |
-
#
|
847 |
def _censor_me(self, p, safer=0.0005):
|
848 |
self._fetch_moderate_engine()
|
849 |
resp_orig = self.ai_client.moderations.create(input=p, model=self.text_model)
|
@@ -912,7 +893,7 @@ def _draw_donut(self,data,labels,col, exp,title):
|
|
912 |
#
|
913 |
@add_method(Pluto_Happy)
|
914 |
# def censor_me(self, msg, safer=0.02, ibutton_1=0):
|
915 |
-
def
|
916 |
# safer=0.2
|
917 |
yjson = self._censor_me(msg,safer)
|
918 |
_canvas = self._draw_censor(yjson)
|
@@ -920,11 +901,9 @@ def censor_me(self, msg, safer):
|
|
920 |
# return (_canvas, _yjson)
|
921 |
return(_canvas)
|
922 |
# %%write -a app.py
|
923 |
-
# result from a lot of prompt AI and old fashion try and error
|
924 |
|
925 |
-
# print(gradio.__version__)
|
926 |
import random
|
927 |
-
|
928 |
def say_hello(val):
|
929 |
return f"Hello: {val}"
|
930 |
def say_toxic():
|
@@ -956,8 +935,8 @@ txt1 = """
|
|
956 |
|
957 |
> This NLP (Natural Language Processing) AI demonstration aims to prevent profanity, vulgarity, hate speech, violence, sexism, and other offensive language.
|
958 |
>It is **not an act of censorship**, as the final UI (User Interface) will give the reader, but not a young reader, the option to click on a label to read the toxic message.
|
959 |
-
>The goal is to create a safer and more respectful environment for you, your colleages, and your family.
|
960 |
-
> This NLP app is 1 of 3 hands-on
|
961 |
---
|
962 |
### π΄ Helpful Instruction:
|
963 |
|
@@ -1015,9 +994,9 @@ txt2 = """
|
|
1015 |
|
1016 |
>An AI Solution Architect (AISA) is a mastermind who possesses a deep understanding of the complex technicalities of AI and knows how to creatively integrate them into real-world solutions. They bridge the gap between theoretical AI models and practical, effective applications. AISA works as a strategist to design AI systems that align with business objectives and technical requirements. They delve into algorithms, data structures, and computational theories to translate them into tangible, impactful AI solutions that have the potential to revolutionize industries.
|
1017 |
|
1018 |
-
> π [Sign up for the course today](https://elvtr.com/course/ai-solution-architect?utm_source=instructor&utm_campaign=AISA&utm_content=linkedin), and I will see you in class.
|
1019 |
|
1020 |
-
- An article about this NLP Text Moderation will be coming soon.
|
1021 |
"""
|
1022 |
txt3 = """
|
1023 |
## π₯ WARNING: WARNING:
|
@@ -1043,7 +1022,7 @@ with gradio.Blocks() as gradio_app:
|
|
1043 |
in1.render()
|
1044 |
in2.render()
|
1045 |
but1.render()
|
1046 |
-
but1.click(monty.
|
1047 |
|
1048 |
with gradio.Column(scale=2):
|
1049 |
out1.render()
|
@@ -1064,5 +1043,6 @@ with gradio.Blocks() as gradio_app:
|
|
1064 |
with gradio.Row():
|
1065 |
gradio.Markdown(txt2)
|
1066 |
# %%write -a app.py
|
1067 |
-
#
|
|
|
1068 |
gradio_app.launch()
|
|
|
57 |
self._ph()
|
58 |
#
|
59 |
# define class var for stable division
|
60 |
+
self._huggingface_crkey="gAAAAABkduT-XeiYtD41bzjLtwsLCe9y1FbHH6wZkOZwvLwCrgmOtNsFUPWVqMVG8MumazFhiUZy91mWEnLDLCFw3eKNWtOboIyON6yu4lctn6RCQ4Y9nJvx8wPyOnkzt7dm5OISgFcm"
|
61 |
+
self._gpt_crkey="'gAAAAABkgiYGQY8ef5y192LpNgrAAZVCP3bo2za9iWSZzkyOJtc6wykLwGjFjxKFpsNryMgEhCATJSonslooNSBJFM3OcnVBz4jj_lyXPQABOCsOWqZm6W9nrZYTZkJ0uWAAGJV2B8uzQ13QZgI7VCZ12j8Q7WfrIg=='"
|
62 |
+
self._fkey="your_key_goes_here"
|
63 |
+
self._github_crkey="gAAAAABksjLYjRoFxZDDW5RgBN_uvm6pqDP128S2qOEfv9PgVL8fwdtXzWvCeMHwnGcibAky5cGs3XNxMH4VgbaPBA3I_CPRp3bRK3TMNU4HGRKxbdMnJ7U04IkVSdcMn8o86z3yhcSn"
|
64 |
+
self._kaggle_crkey="gAAAAABksjOOU2a-BtZ4NV8BkmFhBzqjix7XL9DsKPrua7OaMc7t8QKGw_3Ut5wyv4NL4FHX74JFEEbmpVbsPINN7LcqLtewuyF0o0P9461PY9qLBAGy6Wr7PyE0qwDogQoDGJ1UJgPn"
|
65 |
#
|
66 |
self.fname_id = 0
|
67 |
self.dname_img = "img_colab/"
|
|
|
808 |
return decorator
|
809 |
#
|
810 |
# [END OF pluto_happy]
|
811 |
+
## %%write -a app.py
|
812 |
+
# prompt: create a new class Pluto_Happy and name it monty
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
813 |
|
814 |
+
monty = Pluto_Happy('Monty, Monty Said!')
|
|
|
|
|
|
|
|
|
|
|
815 |
# %%writefile -a app.py
|
816 |
+
# prompt: (combine of many seperate prompts and copy code into one code cell)
|
817 |
+
|
818 |
+
# for openai version 1.3.8
|
819 |
@add_method(Pluto_Happy)
|
820 |
+
#
|
821 |
def _fetch_moderate_engine(self):
|
822 |
+
self.ai_client = openai.OpenAI(api_key=self._openai_key)
|
823 |
self.text_model = "text-moderation-latest"
|
824 |
return
|
825 |
#
|
826 |
@add_method(Pluto_Happy)
|
827 |
+
# f
|
828 |
def _censor_me(self, p, safer=0.0005):
|
829 |
self._fetch_moderate_engine()
|
830 |
resp_orig = self.ai_client.moderations.create(input=p, model=self.text_model)
|
|
|
893 |
#
|
894 |
@add_method(Pluto_Happy)
|
895 |
# def censor_me(self, msg, safer=0.02, ibutton_1=0):
|
896 |
+
def fetch_toxicity_level(self, msg, safer):
|
897 |
# safer=0.2
|
898 |
yjson = self._censor_me(msg,safer)
|
899 |
_canvas = self._draw_censor(yjson)
|
|
|
901 |
# return (_canvas, _yjson)
|
902 |
return(_canvas)
|
903 |
# %%write -a app.py
|
904 |
+
# prompt: result from a lot of prompt AI and old fashion try and error
|
905 |
|
|
|
906 |
import random
|
|
|
907 |
def say_hello(val):
|
908 |
return f"Hello: {val}"
|
909 |
def say_toxic():
|
|
|
935 |
|
936 |
> This NLP (Natural Language Processing) AI demonstration aims to prevent profanity, vulgarity, hate speech, violence, sexism, and other offensive language.
|
937 |
>It is **not an act of censorship**, as the final UI (User Interface) will give the reader, but not a young reader, the option to click on a label to read the toxic message.
|
938 |
+
>The goal is to create a safer and more respectful environment for you, your colleages, and your family.
|
939 |
+
> This NLP app is 1 of 3 hands-on courses, ["AI Solution Architect," from ELVTR and Duc Haba](https://elvtr.com/course/ai-solution-architect?utm_source=instructor&utm_campaign=AISA&utm_content=linkedin).
|
940 |
---
|
941 |
### π΄ Helpful Instruction:
|
942 |
|
|
|
994 |
|
995 |
>An AI Solution Architect (AISA) is a mastermind who possesses a deep understanding of the complex technicalities of AI and knows how to creatively integrate them into real-world solutions. They bridge the gap between theoretical AI models and practical, effective applications. AISA works as a strategist to design AI systems that align with business objectives and technical requirements. They delve into algorithms, data structures, and computational theories to translate them into tangible, impactful AI solutions that have the potential to revolutionize industries.
|
996 |
|
997 |
+
> π [Sign up for the course today](https://elvtr.com/course/ai-solution-architect?utm_source=instructor&utm_campaign=AISA&utm_content=linkedin), and I will see you in class.
|
998 |
|
999 |
+
- An article about this NLP Text Moderation will be coming soon.
|
1000 |
"""
|
1001 |
txt3 = """
|
1002 |
## π₯ WARNING: WARNING:
|
|
|
1022 |
in1.render()
|
1023 |
in2.render()
|
1024 |
but1.render()
|
1025 |
+
but1.click(monty.fetch_toxicity_level, inputs=[in1, in2], outputs=out1)
|
1026 |
|
1027 |
with gradio.Column(scale=2):
|
1028 |
out1.render()
|
|
|
1043 |
with gradio.Row():
|
1044 |
gradio.Markdown(txt2)
|
1045 |
# %%write -a app.py
|
1046 |
+
# prompt: start graido_app
|
1047 |
+
|
1048 |
gradio_app.launch()
|