randydev commited on
Commit
ca36c95
·
verified ·
1 Parent(s): 71a274c

Try remover

Browse files
Files changed (1) hide show
  1. akn/Gemini/gemini.py +38 -4
akn/Gemini/gemini.py CHANGED
@@ -24,6 +24,7 @@ import asyncio
24
  import io
25
  import os
26
  import re
 
27
  from PIL import Image
28
  from pyrogram import *
29
  from pyrogram import enums
@@ -46,6 +47,21 @@ from akenoai.types import DifferentAPIDefault
46
 
47
  js = AkenoXJs(DifferentAPIDefault()).connect()
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  async def geni_files_delete(name: str):
50
  url = f"https://generativelanguage.googleapis.com/v1beta/{name}"
51
  params = {"key": GOOGLE_API_KEY}
@@ -148,11 +164,29 @@ async def chatbot_talk(client: Client, message: Message):
148
  file_path = await message.download()
149
  caption = message.caption or "What's this?"
150
  x = GeminiLatest(api_keys=GOOGLE_API_KEY)
151
- if client.me.is_premium:
152
- ai_reply = await message.reply_text(f"{custom_loading}Processing...")
153
- else:
154
- ai_reply = await message.reply_text(f"Processing...")
155
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
157
  await asyncio.sleep(1.5)
158
  backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
 
24
  import io
25
  import os
26
  import re
27
+ import base64
28
  from PIL import Image
29
  from pyrogram import *
30
  from pyrogram import enums
 
47
 
48
  js = AkenoXJs(DifferentAPIDefault()).connect()
49
 
50
+ async def remove_bg_myapi(return_image):
51
+ with open(return_image, "rb") as image_file:
52
+ encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
53
+ payload = {
54
+ "image_base64": encoded_string
55
+ }
56
+ response = requests.post("https://randydev-meta-ai.hf.space/remove-bg-base64", json=payload)
57
+ if response.status_code == 200:
58
+ result_base64 = response.json().get("output_image_base64")
59
+ with open("output.png", "wb") as out_file:
60
+ out_file.write(base64.b64decode(result_base64))
61
+ return return_image
62
+ else:
63
+ return None
64
+
65
  async def geni_files_delete(name: str):
66
  url = f"https://generativelanguage.googleapis.com/v1beta/{name}"
67
  params = {"key": GOOGLE_API_KEY}
 
164
  file_path = await message.download()
165
  caption = message.caption or "What's this?"
166
  x = GeminiLatest(api_keys=GOOGLE_API_KEY)
 
 
 
 
167
  try:
168
+ new_check_bg = re.findall(r"\bremover\b", caption)
169
+ if caption == "remover":
170
+ return await message.reply_text("i don't have, what do you mean by create remover?")
171
+ if new_check_bg:
172
+ new_js = None
173
+ new_js = await message.reply_text("Please wait, it's still being processed")
174
+ response_path = await remove_bg_myapi(file_path)
175
+ if not response_path:
176
+ return await message.reply_text("Error try remover bg")
177
+ await new_js.edit_text("Uploading image completed...")
178
+ await message.reply_photo(
179
+ response_path,
180
+ progress=progress,
181
+ progress_args=(
182
+ new_js,
183
+ time.time(),
184
+ "Uploading image completed..."
185
+ )
186
+ )
187
+ await new_js.delete()
188
+ return
189
+ ai_reply = await message.reply_text(f"Processing...")
190
  await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
191
  await asyncio.sleep(1.5)
192
  backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)