33# YOu can check it out for uses example
44import os
55
6- from pyrogram import Client, filters, enums
6+ from pyrogram import Client, enums, filters
77from pyrogram.types import Message
8+ from utils.scripts import format_exc, import_library
89
910from utils import modules_help, prefix
10- from utils.scripts import format_exc, import_library
1111
1212genai = import_library("google.genai", "google-genai")
1313
2424
2525MODEL_NAME = "gemini-2.5-flash"
2626
27+
2728@Client.on_message(filters.command("getai", prefix) & filters.me)
2829async def getai(_, message: Message):
2930 local_file_path = None
3031 uploaded_file = None
3132 try:
3233 await message.edit_text("<code>Please Wait...</code>")
33-
34+
3435 try:
3536 if not message.reply_to_message or not message.reply_to_message.media:
36- return await message.edit_text("<code>Please reply to an image...</code>")
37-
37+ return await message.edit_text(
38+ "<code>Please reply to an image...</code>"
39+ )
40+
3841 local_file_path = await message.reply_to_message.download()
3942 except Exception:
40- return await message.edit_text("<code>Please reply to an image or media that can be downloaded.</code>")
43+ return await message.edit_text(
44+ "<code>Please reply to an image or media that can be downloaded.</code>"
45+ )
4146
4247 uploaded_file = client.files.upload(file=local_file_path)
43-
48+
4449 prompt = "Get details of given image, be as accurate as possible."
4550
4651 response = client.models.generate_content(
47- model=MODEL_NAME,
48- contents=[prompt, uploaded_file]
52+ model=MODEL_NAME, contents=[prompt, uploaded_file]
4953 )
5054
5155 await message.edit_text(
@@ -68,34 +72,32 @@ async def aicook(_, message: Message):
6872 uploaded_file = None
6973 if not message.reply_to_message or not message.reply_to_message.media:
7074 return await message.edit_text("<code>Please reply to an image...</code>")
71-
75+
7276 try:
7377 await message.edit_text("<code>Cooking...</code>")
7478
7579 try:
7680 local_file_path = await message.reply_to_message.download()
7781 except Exception:
78- return await message.edit_text("<code>Please reply to an image or media that can be downloaded.</code>")
82+ return await message.edit_text(
83+ "<code>Please reply to an image or media that can be downloaded.</code>"
84+ )
7985
8086 uploaded_file = client.files.upload(file=local_file_path)
81-
87+
8288 cook_contents = [
8389 "Accurately identify the baked good in the image and provide an appropriate and recipe consistent with your analysis. ",
8490 uploaded_file,
8591 ]
8692
8793 response = client.models.generate_content(
88- model=MODEL_NAME,
89- contents=cook_contents,
90- config=generation_config_cook
94+ model=MODEL_NAME, contents=cook_contents, config=generation_config_cook
9195 )
9296
93- await message.edit_text(
94- f"{response.text}", parse_mode=enums.ParseMode.MARKDOWN
95- )
97+ await message.edit_text(f"{response.text}", parse_mode=enums.ParseMode.MARKDOWN)
9698 except Exception as e:
9799 await message.edit_text(f"An error occurred: {format_exc(e)}")
98-
100+
99101 finally:
100102 if uploaded_file:
101103 client.files.delete(name=uploaded_file.name)
@@ -108,11 +110,13 @@ async def aiseller(_, message: Message):
108110 local_file_path = None
109111 uploaded_file = None
110112 if not message.reply_to_message or not message.reply_to_message.media:
111- return await message.edit_text("<code>Please reply to a product image...</code>")
113+ return await message.edit_text(
114+ "<code>Please reply to a product image...</code>"
115+ )
112116
113117 try:
114118 await message.edit_text("<code>Generating...</code>")
115-
119+
116120 if len(message.command) > 1:
117121 taud = message.text.split(maxsplit=1)[1]
118122 else:
@@ -123,10 +127,12 @@ async def aiseller(_, message: Message):
123127 try:
124128 local_file_path = await message.reply_to_message.download()
125129 except Exception:
126- return await message.edit_text("<code>Please reply to an image or media that can be downloaded.</code>")
130+ return await message.edit_text(
131+ "<code>Please reply to an image or media that can be downloaded.</code>"
132+ )
127133
128134 uploaded_file = client.files.upload(file=local_file_path)
129-
135+
130136 sell_contents = [
131137 "Given an image of a product and its target audience, write an engaging marketing description",
132138 "Product Image: ",
@@ -140,18 +146,17 @@ async def aiseller(_, message: Message):
140146 contents=sell_contents,
141147 )
142148
143- await message.edit_text(
144- f"{response.text}", parse_mode=enums.ParseMode.MARKDOWN
145- )
149+ await message.edit_text(f"{response.text}", parse_mode=enums.ParseMode.MARKDOWN)
146150 except Exception as e:
147151 await message.edit_text(f"An error occurred: {format_exc(e)}")
148-
152+
149153 finally:
150154 if uploaded_file:
151155 client.files.delete(name=uploaded_file.name)
152156 if local_file_path and os.path.exists(local_file_path):
153157 os.remove(local_file_path)
154158
159+
155160modules_help["aimage"] = {
156161 "getai [reply to image]*": "Get details of image with Ai",
157162 "aicook [reply to image]*": "Generate Cooking instrunctions of the given food image",
0 commit comments