From 8a74df659815b5e38b509f4d220e50d2ac6f0edd Mon Sep 17 00:00:00 2001 From: Fedor Sevrugin Date: Thu, 10 Jul 2025 00:15:33 +0300 Subject: [PATCH 1/1] V1.0 --- README.md | 0 fhentaibot.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 README.md create mode 100755 fhentaibot.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/fhentaibot.py b/fhentaibot.py new file mode 100755 index 0000000..2bc553b --- /dev/null +++ b/fhentaibot.py @@ -0,0 +1,65 @@ +from telegram import Update, File +from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters +import nest_asyncio +import requests +from PIL import Image +from transformers import pipeline +import os + + +nest_asyncio.apply() +TOKEN = '' # Replace with your actual token + + +async def start(update: Update, context) -> None: + await update.message.reply_text('Hi! I\'m your NSFW Image Detector Bot. Send me an image to check if it contains NSFW content.') + + +async def analyze_image(update: Update, context) -> None: + file_id = update.message.photo[-1].file_id + file_info = await context.bot.get_file(file_id) + + if file_info: + # Get the URL of the file + file_path = file_info.file_path + response = requests.get(file_path) + + if response.status_code == 200: + # Save the photo to disk + file_name = f"{file_id}.jpg" + with open(file_name, 'wb') as f: + f.write(response.content) + else: + await update.message.reply_text('Failed to download the photo.') + else: + await update.message.reply_text('Failed to download the photo.') + + try: + img = Image.open(file_name) + classifier = pipeline("image-classification", model="Falconsai/nsfw_image_detection") + results = classifier(img) + + if results[0]['label'] == 'nsfw': + await update.message.reply_text(f"Warning: This image contains NSFW content.") + await context.bot.delete_message(chat_id=update.message.chat_id,message_id=update.message.message_id) + + except Exception as e: + await update.message.reply_text(f'Some kind of mistake') + print(f"An error occurred: {e}") + + finally: + os.remove(file_name) + + +async def main() -> None: + application = ApplicationBuilder().token(TOKEN).build() + + application.add_handler(CommandHandler('start', start)) + application.add_handler(MessageHandler(filters.PHOTO, analyze_image)) + + await application.run_polling() + + +if __name__ == '__main__': + import asyncio + asyncio.run(main()) -- 2.30.2