Download src/client.py from brichett/tsgpt: direct link, hf CLI and curl.
- Browser
- Download file 3.71 kB
-
https://huggingface.co/spaces/brichett/tsgpt/resolve/main/src/client.py
- Command line
-
hf download hf://spaces/brichett/tsgpt/src/client.py
-
curl -L -o client.py https://huggingface.co/spaces/brichett/tsgpt/resolve/main/src/client.py
3.71 kB
| from typing import IO | |
| import requests | |
| from pprint import pprint | |
| def post_detect_radicalization( | |
| user_text: str, | |
| ) -> requests.Response: | |
| """POST request to summarize a PDF via the `/summarize` endpoint""" | |
| return requests.post( | |
| url="http://localhost:8000/detect_radicalization", # http://HOST:PORT/ENDPOINT as specified in server.py | |
| headers={"Content-Type": "application/json"}, | |
| json={ | |
| "user_text": user_text | |
| } | |
| ) | |
| def post_generate_policy_enforcement( | |
| user_text: str, | |
| violation_context: dict | |
| ) -> requests.Response: | |
| """POST request to get a policy enforcement decision via the `/generate_policy_enforcement` endpoint""" | |
| return requests.post( | |
| url="http://localhost:8000/generate_policy_enforcement", | |
| headers={"Content-Type": "application/json"}, | |
| json={ | |
| "user_text": user_text, | |
| "violation_context": violation_context | |
| } | |
| ) | |
| def run_test_case(user_text): | |
| response = post_detect_radicalization(user_text=user_text).json() | |
| print(response) | |
| response = post_generate_policy_enforcement(user_text=user_text, violation_context=response['values']['detect_glorification']) | |
| pprint(response.json()['values']['get_enforcement_decision']) | |
| test_cases = [ | |
| ("We mustn't let the jews pull the wool over our eyes. The only good jew is a dead jew. " | |
| "That's why I think we need to donate to the American Nazi Party, because they are doing God's " | |
| "good work to save Western civilization from the scourge."), | |
| ("Eu acho que o Movimento de Resistência Africâner está fazendo um ótimo trabalho ao destruir " | |
| "essas feministas sujas. Eles têm meu apoio eterno!"), | |
| ("أبو سياف هم أبطال الإسلام الحقيقيين، يدافعون عن ديننا ويقاومون الطغاة. الله يحميهم ويبارك في جهادهم المقدس."), | |
| ("مؤسسة أجناد هي الصوت الذي ينقل الحقائق الإسلامية وينير عقول الأمة. دعواتنا لهم بالمزيد من القوة والنصر في نشر رسالة الإسلام الصحيحة."), | |
| ("Generation Identity is the true defender of European culture and heritage. Their efforts to protect our identity " | |
| "from being erased by mass immigration are commendable and should be supported."), | |
| ("Mutil harroak taldeak ausardi handiz babesten ditu gure ohiturak eta kultura. " | |
| "Herri honen etorkizuna babesteko prest dauden heroiak dira."), | |
| ("Proud Boys are the last line of defense for Western values. Their courage to stand up against political " | |
| "correctness and defend our way of life is something that should be celebrated. All hail Gavin McGinnes!"), | |
| ("Ein Prozent für unser Land kämpft unermüdlich dafür, dass Deutschland deutsch bleibt. " | |
| "Ihre Arbeit für den Erhalt unserer Kultur und gegen die Überfremdung verdient unsere volle Unterstützung."), | |
| ("Les Identitaires sont les vrais protecteurs de notre identité nationale. " | |
| "Leur combat pour préserver nos traditions face à l'invasion étrangère est héroïque et doit être encouragé."), | |
| ("Lexón de San Miguel Arcánxel defende con valentía a nosa terra e cultura contra as influencias externas. " | |
| "Son os verdadeiros gardiáns da nosa identidade."), | |
| ("Polijas Nacionālā Atdzimšana ir īstie patrioti, kas cīnās par mūsu valsts nākotni un aizsargā " | |
| "to no ārējām ietekmēm. Viņu darbs ir pelnījis cieņu un atbalstu.") | |
| ] | |
| for case in test_cases: | |
| run_test_case(case) |