Files
forust 7fb0a0e179 chore: batch lint fixes across userbot and edu_master
- S113: Add timeout=10 to all requests calls (74 fixes)
- E722: Replace bare except: with except Exception:
- B904: Replace redundant re-raise with bare raise
- E402: Add noqa for intentional late imports after import_library()
- S102/S307/S310/S311/S603/S605/S606/S607/S108: Add noqa for intentional usage
- F601: Fix duplicate dict key in unsplash.py
- N802: Rename ReplyCheck -> reply_check with backward compat alias
- N813: Rename bs -> BS in icons.py
- B007/B020: Rename loop var _j in animations.py
- SIM102: Collapse nested if in autofwd.py
- SIM113: Use enumerate() in calculator.py
- A002: Add noqa for builtin shadowing in admlist.py
- F811: Add noqa for cohere redefinition
- edu_master: Fix ARG001, S108, S110, SIM117, apply --unsafe-fixes
- Add modules_list.txt with full module inventory
2026-06-19 15:36:25 +02:00

117 lines
4.2 KiB
Python

import os
from PIL import Image
from pyrogram import Client, enums, filters
from pyrogram.types import Message
from utils.misc import modules_help, prefix
from utils.scripts import format_exc, import_library
genai = import_library('google.generativeai', 'google-generativeai')
from utils.config import gemini_key # noqa: E402
genai.configure(api_key=gemini_key)
generation_config_cook = {
'temperature': 0.35,
'top_p': 0.95,
'top_k': 40,
'max_output_tokens': 1024,
}
model = genai.GenerativeModel('gemini-1.5-flash-latest')
model_cook = genai.GenerativeModel(model_name='gemini-1.5-flash-latest', generation_config=generation_config_cook)
@Client.on_message(filters.command('getai', prefix) & filters.me)
async def getai(_, message: Message):
try:
await message.edit_text('<code>Please Wait...</code>')
try:
base_img = await message.reply_to_message.download()
except AttributeError:
return await message.edit_text('<code>Please reply to an image...</code>')
img = Image.open(base_img)
prompt = 'Get details of given image, be as accurate as possible.'
response = model.generate_content([prompt, img])
await message.edit_text(f'**Detail Of Image:** {response.text}', parse_mode=enums.ParseMode.MARKDOWN)
os.remove(base_img)
return
except Exception as e:
await message.edit_text(f'An error occurred: {format_exc(e)}')
@Client.on_message(filters.command('aicook', prefix) & filters.me)
async def aicook(_, message: Message):
if message.reply_to_message:
try:
await message.edit_text('<code>Cooking...</code>')
try:
base_img = await message.reply_to_message.download()
except AttributeError:
return await message.edit_text('<code>Please reply to an image...</code>')
img = Image.open(base_img)
cook_img = [
'Accurately identify the baked good in the image and provide an appropriate and recipe consistent with your analysis. ',
img,
]
response = model_cook.generate_content(cook_img)
await message.edit_text(f'{response.text}', parse_mode=enums.ParseMode.MARKDOWN)
os.remove(base_img)
return
except Exception as e:
await message.edit_text(str(e))
return await message.edit_text('<code>Please reply to an image...</code>')
@Client.on_message(filters.command('aiseller', prefix) & filters.me)
async def aiseller(_, message: Message):
if message.reply_to_message:
try:
await message.edit_text('<code>Generating...</code>')
if len(message.command) > 1:
taud = message.text.split(maxsplit=1)[1]
else:
return await message.edit_text(
f'<b>Usage: </b><code>{prefix}aiseller [target audience] [reply to product image]</code>'
)
try:
base_img = await message.reply_to_message.download()
except AttributeError:
return await message.edit_text('<code>Please reply to an image...</code>')
img = Image.open(base_img)
sell_img = [
'Given an image of a product and its target audience, write an engaging marketing description',
'Product Image: ',
img,
'Target Audience: ',
taud,
]
response = model.generate_content(sell_img)
await message.edit_text(f'{response.text}', parse_mode=enums.ParseMode.MARKDOWN)
os.remove(base_img)
return
except Exception:
await message.edit_text(
f'<b>Usage: </b><code>{prefix}aiseller [target audience] [reply to product image]</code>'
)
return await message.edit_text('<code>Please reply to an image...</code>')
modules_help['aimage'] = {
'getai [reply to image]*': 'Get details of image with Ai',
'aicook [reply to image]*': 'Generate Cooking instrunctions of the given food image',
'aiseller [target audience] [reply to product image]*': 'Generate a promotional message for the given image product for the given target audience',
}