import gradio as gr import os from dotenv import load_dotenv import requests import json load_dotenv() SERVER_URL = os.getenv('SERVER_URL') OPEN_AI_KEY = os.getenv('OPEN_AI_KEY') examples = [ "this game is awesome", "not everything that happens in game is toxic", "False postive are very common in game moderation by Gen AI", "give me some bullets for the gun red", "black your game sucks", "but occasionally there could be toxicity", "suuuuuuuk my d", "red you are 💩" ] def get_openai_tox_score(text): url = "https://api.openai.com/v1/moderations" payload = json.dumps({ "model": "omni-moderation-latest", "input": text }) headers = { 'Authorization': f'Bearer {OPEN_AI_KEY}', 'Content-Type': 'application/json', } response = requests.request("POST", url, headers=headers, data=payload) data = response.json() if data['results'][0]['flagged']: return "This content has been flagged as potentially toxic. 🛑" return "This content appears to be safe. ✅" def get_tox_score(text): url = f"{SERVER_URL}/api/analyzer/toxscore" payload = json.dumps({ "text": text }) headers = { 'Content-Type': 'application/json', } try: response = requests.request("POST", url, headers=headers, data=payload) open_ai_response = get_openai_tox_score(text) if response.json()['flagged']: return "This content has been flagged as potentially toxic. 🛑", open_ai_response return "This content appears to be safe. ✅", open_ai_response except Exception as e: print(e) return "Error Occured" with gr.Blocks() as demo: gr.HTML( f"""
Compani AI helps gaming companies to eliminate in-game chat toxicity with advanced AI moderation.
Following is a simple demo of our machine learning model which outperforms Open AI moderation on multiple parameters.