akn-dev / akn /Akeno /fluxai.py
randydev's picture
fix update
b27e2d7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2020-2024 (c) Randy W @xtdevs, @xtsea
#
# from : https://github.com/TeamKillerX
# Channel : @RendyProjects
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import time
import os
from pyrogram import *
from pyrogram import Client, filters
from pyrogram.types import *
from pyrogram.errors import *
from akn import log_detailed_error
from akn.utils.handler import *
from akn.utils.logger import LOGS
from akn.utils.scripts import progress
from config import *
from akn.utils.prefixprem import command
from akenoai import *
from akenoai.types import DifferentAPIDefault
from . import ReplyCheck
custom_loading = "<emoji id=5974235702701853774>๐Ÿ—ฟ</emoji>"
@Akeno(
command(["fluxai"])
& filters.me
& ~filters.forwarded
)
async def imgfluxai_(client: Client, message: Message):
question = message.text.split(" ", 1)[1] if len(message.command) > 1 else None
if not question:
return await message.reply_text("Please provide a question for Flux.")
if client.me.is_premium:
pro = await message.reply_text(f"{custom_loading}Generating image, please wait...")
else:
pro = await message.reply_text("Generating image, please wait...")
try:
js = AkenoXJs(DifferentAPIDefault()).connect()
response = await js.image.create(
"black-forest-labs/flux-1-schnell",
image_read=True,
params_data={"query": question},
)
file_path = "randydev.jpg"
with open(file_path, "wb") as f:
f.write(response)
await pro.edit_text("Uploading image...")
await message.reply_photo(
file_path,
progress=progress,
progress_args=(
pro,
time.time(),
"Uploading image..."
),
reply_to_message_id=ReplyCheck(message)
)
await pro.delete()
if os.path.exists(file_path):
os.remove(file_path)
except ChatSendPhotosForbidden:
return await pro.edit_text("You can't send photos in this chat")
except Exception as e:
await log_detailed_error(e, where=client.me.id, who=message.chat.title)
await pro.edit_text("error generating the image.")
module = modules_help.add_module("fluxai", __file__)
module.add_command("fluxai", "to question flux image generator.")