Spaces:
Running
Running
taslim19
commited on
Commit
·
27bdbc9
1
Parent(s):
2687e85
Update waifu_name.py: use image hash matching for waifu name lookup
Browse files
DragMusic/plugins/management/waifu_name.py
CHANGED
@@ -1,23 +1,32 @@
|
|
1 |
from pyrogram import filters
|
2 |
from DragMusic import app
|
3 |
from DragMusic.core.userbot import Userbot
|
|
|
|
|
|
|
4 |
|
5 |
-
WAIFU_CHANNEL_ID = "Grabber_Database" # Use channel username
|
6 |
|
7 |
-
async def
|
8 |
userbot = Userbot().one
|
9 |
async with userbot:
|
10 |
async for msg in userbot.get_chat_history(WAIFU_CHANNEL_ID):
|
11 |
-
if msg.photo
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
return None
|
14 |
|
15 |
@app.on_message(filters.command("waifus") & filters.reply)
|
16 |
async def waifus_name(client, message):
|
17 |
if not message.reply_to_message or not message.reply_to_message.photo:
|
18 |
return await message.reply("Reply to a waifu image to get the name!")
|
19 |
-
|
20 |
-
|
|
|
|
|
21 |
if waifu_name:
|
22 |
await message.reply(f"The waifu's name is: {waifu_name}")
|
23 |
else:
|
|
|
1 |
from pyrogram import filters
|
2 |
from DragMusic import app
|
3 |
from DragMusic.core.userbot import Userbot
|
4 |
+
from PIL import Image
|
5 |
+
import imagehash
|
6 |
+
import io
|
7 |
|
8 |
+
WAIFU_CHANNEL_ID = "Grabber_Database" # Use channel username
|
9 |
|
10 |
+
async def get_waifu_name_by_image_hash(target_hash):
|
11 |
userbot = Userbot().one
|
12 |
async with userbot:
|
13 |
async for msg in userbot.get_chat_history(WAIFU_CHANNEL_ID):
|
14 |
+
if msg.photo:
|
15 |
+
file = await userbot.download_media(msg, in_memory=True)
|
16 |
+
img = Image.open(io.BytesIO(file.getvalue()))
|
17 |
+
waifu_hash = imagehash.average_hash(img)
|
18 |
+
if waifu_hash - target_hash < 3: # 0 is identical, <3 is very similar
|
19 |
+
return msg.caption
|
20 |
return None
|
21 |
|
22 |
@app.on_message(filters.command("waifus") & filters.reply)
|
23 |
async def waifus_name(client, message):
|
24 |
if not message.reply_to_message or not message.reply_to_message.photo:
|
25 |
return await message.reply("Reply to a waifu image to get the name!")
|
26 |
+
file = await message.reply_to_message.download(in_memory=True)
|
27 |
+
img = Image.open(io.BytesIO(file.getvalue()))
|
28 |
+
target_hash = imagehash.average_hash(img)
|
29 |
+
waifu_name = await get_waifu_name_by_image_hash(target_hash)
|
30 |
if waifu_name:
|
31 |
await message.reply(f"The waifu's name is: {waifu_name}")
|
32 |
else:
|
requirements.txt
CHANGED
@@ -44,5 +44,6 @@ fastapi
|
|
44 |
torch
|
45 |
transformers
|
46 |
pillow
|
|
|
47 |
# ffmpeg is installed at the system level, but if you want a Python wrapper, uncomment the next line:
|
48 |
# ffmpeg-python
|
|
|
44 |
torch
|
45 |
transformers
|
46 |
pillow
|
47 |
+
imagehash
|
48 |
# ffmpeg is installed at the system level, but if you want a Python wrapper, uncomment the next line:
|
49 |
# ffmpeg-python
|