self-trained2 / ai_ads.py
DeepImagix's picture
Update ai_ads.py
6478736 verified
# ai_ads.py
import random
from datetime import datetime
from pymongo import MongoClient
import os
# MongoDB setup
MONGO_URI = os.getenv("MONGO_URI", "")
mongo_client = MongoClient(MONGO_URI)
ad_db = mongo_client["anime_ai_db"]
ad_logs = ad_db["ad_logs"]
# Example ad messages (can be replaced or extended from DB)
AD_MESSAGES = [
{
"text": "๐Ÿ—„๏ธ Download Android ID to view your android system information such as Ram, Battery life, CPU, and etc, click this ad to view!",
"url": "https://android-id.en.uptodown.com/android",
"id": "android_id_001"
},
{
"text": "๐Ÿ–ผ๏ธ With DeepImagix you can create amazing portrays with different models, a text to image AI, now for free!",
"url": "https://deepimagix-ai.en.uptodown.com/android",
"id": "deepimagix_002"
},
{
"text": "โ›“๏ธ Protect your privacy online by connecting to ACE INJECTOR VPN, good for internet speed and privacy!",
"url": "https://ace-injector-ssh-v2r-dns-proxy-vpn.en.uptodown.com/android",
"id": "ace_injector_003"
},
{
"text": "๐Ÿค– Interested in coding.?Download Android IDE to creat your first android application!",
"url": "https://androidide-coder.en.uptodown.com/android",
"id": "androidide_005"
},
{
"text": "๐Ÿ’Ž Did you know you can turn off ads or reduce them by subscribing to our premium package, our premium package includes, Fast AI reply, Reduced AI ads, more anime characters etc, you can subscribe for just only ๐Ÿ’ฐ$30 once-off!",
"url": "",
"id": "pro_upgrade_006"
},
{
"text": "๐ŸŽ‰ Want to advertise your business here.?email us at alysium.corporation.studios@gmail.com to buy ad, can be seen from over 10 000 users!",
"url": "",
"id": "ad_revenue_007"
},
{
"text": "๐Ÿ’ŒTIP!! To talk to it like you talk to your best friend, it can be helpful.",
"url": "",
"id": "no_ad_008"
},
{
"text": "๐ŸŽฎ Optimise your gaming experience with GTA LAG fixer, Reduces lagging and increases fps for Grand theft auto san andreas!",
"url": "https://gta-lag-fixer-increase-fps.en.uptodown.com/android",
"id": "gta_lag_009"
}
]
def pick_ad() -> dict:
"""Randomly select an ad from the pool."""
return random.choice(AD_MESSAGES)
def inject_ad(response_text: str, user_id: str) -> str:
"""Add an ad to the AI response with a probability."""
if random.random() < 0.25: # 25% chance to inject ad
ad = pick_ad()
log_ad_display(user_id, ad["id"])
ad_text = f"\n\n๐Ÿ“ข **Sponsored AD**: [{ad['text']}]({ad['url']})"
return response_text + ad_text
return response_text
def log_ad_display(user_id: str, ad_id: str):
"""Log the ad display to MongoDB."""
ad_logs.insert_one({
"user_id": user_id,
"ad_id": ad_id,
"event": "impression",
"timestamp": datetime.utcnow()
})
def log_ad_click(user_id: str, ad_id: str):
"""Log when a user clicks on an ad."""
ad_logs.insert_one({
"user_id": user_id,
"ad_id": ad_id,
"event": "click",
"timestamp": datetime.utcnow()
})