File size: 3,012 Bytes
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b27e2d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/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.")