Update Akeno/plugins/imageai.py
Browse files- Akeno/plugins/imageai.py +10 -9
Akeno/plugins/imageai.py
CHANGED
@@ -33,31 +33,32 @@ async def schellwithflux(args):
|
|
33 |
headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
|
34 |
payload = {"inputs": args}
|
35 |
response = requests.post(API_URL, headers=headers, json=payload)
|
36 |
-
if
|
37 |
LOGS.error(f"Error status {response.status_code}")
|
38 |
-
return
|
39 |
return response.content
|
40 |
|
41 |
@Akeno(
|
42 |
-
|
43 |
-
& filters.command(["fluxai"], CMD_HANDLER)
|
44 |
& filters.me
|
45 |
& ~filters.forwarded
|
46 |
)
|
47 |
async def imgfluxai_(client: Client, message: Message):
|
48 |
question = message.text.split(" ", 1)[1] if len(message.command) > 1 else None
|
49 |
if not question:
|
50 |
-
return await message.reply_text("
|
51 |
try:
|
52 |
if not HUGGING_TOKEN:
|
53 |
-
return await message.reply_text("
|
54 |
image_bytes = await schellwithflux(question)
|
55 |
-
|
|
|
|
|
56 |
with Image.open(io.BytesIO(image_bytes)) as img:
|
57 |
img.save("testing.jpg", format="JPEG")
|
58 |
-
ok = await pro.edit_text("Uploading
|
59 |
await message.reply_photo("testing.jpg")
|
60 |
await ok.delete()
|
61 |
except Exception as e:
|
62 |
LOGS.error(str(e))
|
63 |
-
await pro.edit_text(str(e))
|
|
|
33 |
headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
|
34 |
payload = {"inputs": args}
|
35 |
response = requests.post(API_URL, headers=headers, json=payload)
|
36 |
+
if response.status_code != 200:
|
37 |
LOGS.error(f"Error status {response.status_code}")
|
38 |
+
return None
|
39 |
return response.content
|
40 |
|
41 |
@Akeno(
|
42 |
+
filters.command(["fluxai"], CMD_HANDLER)
|
|
|
43 |
& filters.me
|
44 |
& ~filters.forwarded
|
45 |
)
|
46 |
async def imgfluxai_(client: Client, message: Message):
|
47 |
question = message.text.split(" ", 1)[1] if len(message.command) > 1 else None
|
48 |
if not question:
|
49 |
+
return await message.reply_text("Please provide a question for Flux.")
|
50 |
try:
|
51 |
if not HUGGING_TOKEN:
|
52 |
+
return await message.reply_text("`HUGGING_TOKEN` is required to use this feature.")
|
53 |
image_bytes = await schellwithflux(question)
|
54 |
+
if image_bytes is None:
|
55 |
+
return await message.reply_text("Failed to generate an image.")
|
56 |
+
pro = await message.reply_text("Generating image, please wait...")
|
57 |
with Image.open(io.BytesIO(image_bytes)) as img:
|
58 |
img.save("testing.jpg", format="JPEG")
|
59 |
+
ok = await pro.edit_text("Uploading image...")
|
60 |
await message.reply_photo("testing.jpg")
|
61 |
await ok.delete()
|
62 |
except Exception as e:
|
63 |
LOGS.error(str(e))
|
64 |
+
await pro.edit_text(f"An error occurred: {str(e)}")
|