Abhi the modder patch 1 (#53)
* Update config.py * Add: SDXL, Upscale * Update termux-install.sh * Update install.sh
This commit is contained in:
10
install.sh
10
install.sh
@@ -80,6 +80,15 @@ if [[ $gemini_key = "" ]]; then
|
||||
echo "NOTE: API Not set you'll not be able to use AI modules"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Enter VCA_API_KEY for aiutils"
|
||||
echo "Learn How to Get One --> https://github.com/VisionCraft-org/VisionCraft?tab=readme-ov-file#obtaining-an-api-key"
|
||||
read -r -p "VCA_API_KEY > " vca_api_key
|
||||
|
||||
if [[ $vca_api_key = "" ]]; then
|
||||
echo "NOTE: API Not set you'll not be able to use aiutils module/pligins"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Choose database type:"
|
||||
echo "[1] MongoDB db_url"
|
||||
@@ -131,6 +140,7 @@ APIFLASH_KEY=${apiflash_key}
|
||||
RMBG_KEY=${rmbg_key}
|
||||
VT_KEY=${vt_key}
|
||||
GEMINI_KEY=${gemini_key}
|
||||
VCA_API_KEY=${vca_api_key}
|
||||
EOL
|
||||
|
||||
chown -R $SUDO_USER:$SUDO_USER .
|
||||
|
||||
95
modules/aiutils.py
Normal file
95
modules/aiutils.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import requests, base64, os
|
||||
|
||||
from pyrogram import Client, enums, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.config import vca_api_key
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import format_exc, edit_or_reply
|
||||
|
||||
# Define the API endpoint
|
||||
api_url = "https://visioncraftapi--vladalek05.repl.co"
|
||||
|
||||
def upscale_request(image):
|
||||
b = base64.b64encode(image).decode('utf-8')
|
||||
payload = {
|
||||
"token": vca_api_key,
|
||||
"image": b
|
||||
}
|
||||
url = 'https://visioncraftapi.vladalek05.repl.co/beta/upscale'
|
||||
headers = {"content-type": "application/json"}
|
||||
|
||||
resp = requests.post(url, json=payload, headers=headers)
|
||||
return resp.content
|
||||
|
||||
@Client.on_message(filters.command("vdxl", prefix) & filters.me)
|
||||
async def vdxl(c: Client, message: Message):
|
||||
try:
|
||||
chat_id = message.chat.id
|
||||
await message.edit_text("<code>Please Wait...</code>")
|
||||
|
||||
if len(message.command) > 1:
|
||||
prompt = message.text.split(maxsplit=1)[1]
|
||||
elif message.reply_to_message:
|
||||
prompt = message.reply_to_message.text
|
||||
else:
|
||||
await message.edit_text(
|
||||
f"<b>Usage: </b><code>{prefix}sdxl [prompt/reply to message]</code>"
|
||||
)
|
||||
return
|
||||
|
||||
data = {
|
||||
"model": "sdxl-turbo",
|
||||
"prompt": prompt,
|
||||
"negative_prompt": "",
|
||||
"image_count": 1,
|
||||
"token": vca_api_key,
|
||||
"width": 1024,
|
||||
"height": 1024,
|
||||
"enhance": False
|
||||
}
|
||||
|
||||
# Send the request to generate images
|
||||
response = requests.post(f"{api_url}/generate-xl", json=data, verify=False)
|
||||
|
||||
# Extract the image URLs from the response
|
||||
image_urls = response.json()["images"]
|
||||
|
||||
# Download and save the generated images
|
||||
for i, image_url in enumerate(image_urls):
|
||||
# Get the image data from the URL
|
||||
response = requests.get(image_url)
|
||||
# Save the image locally
|
||||
with open(f"generated_image_{i}.png", "wb") as f:
|
||||
f.write(response.content)
|
||||
await message.delete()
|
||||
await c.send_photo(chat_id, photo=f"generated_image_{i}.png", caption=f"<b>Prompt:</b><code>{prompt}</code>\n<b>Model:</b><code>sdxl-turbo</code>")
|
||||
except Exception as e:
|
||||
await message.edit_text(f"An error occurred: {format_exc(e)}")
|
||||
finally:
|
||||
os.remove(f"generated_image_{i}.png")
|
||||
|
||||
|
||||
@Client.on_message(filters.command("upscale", prefix) & filters.me)
|
||||
async def upscale(client: Client, message: Message):
|
||||
try:
|
||||
photo_data = await message.download()
|
||||
except ValueError:
|
||||
try:
|
||||
photo_data = await message.reply_to_message.download()
|
||||
except ValueError:
|
||||
await message.edit("<b>File not found</b>", parse_mode=enums.ParseMode.HTML)
|
||||
return
|
||||
await message.edit("<code>Processing...</code>", parse_mode=enums.ParseMode.HTML)
|
||||
image = open(photo_data, 'rb').read()
|
||||
upscaled_image = upscale_request(image)
|
||||
with open('upscaled_image.png', 'wb') as f:
|
||||
f.write(upscaled_image)
|
||||
await message.delete()
|
||||
await client.send_document(message.chat.id, 'upscaled_image.png', caption="Upscaled!")
|
||||
os.remove('upscaled_image.png')
|
||||
|
||||
modules_help["aiutils"] = {
|
||||
"vdxl [prompt]*": "Text to Image with SDXL model",
|
||||
"upscale [cap/reply to image]*": "As the name says",
|
||||
}
|
||||
@@ -78,6 +78,15 @@ if [[ $vt_key = "" ]]; then
|
||||
echo "NOTE: API Not set you'll not be able to use VirusTotal module"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "Enter VCA_API_KEY for aiutils"
|
||||
echo "Learn How to Get One --> https://github.com/VisionCraft-org/VisionCraft?tab=readme-ov-file#obtaining-an-api-key"
|
||||
read -r -p "VCA_API_KEY > " vca_api_key
|
||||
|
||||
if [[ $vca_api_key = "" ]]; then
|
||||
echo "NOTE: API Not set you'll not be able to use aiutils module/pligins"
|
||||
fi
|
||||
|
||||
echo "Choose database type:"
|
||||
echo "[1] MongoDB (your url)"
|
||||
echo "[2] Sqlite"
|
||||
@@ -110,6 +119,7 @@ APIFLASH_KEY=${apiflash_key}
|
||||
RMBG_KEY=${rmbg_key}
|
||||
VT_KEY=${vt_key}
|
||||
GEMINI_KEY=${gemini_key}
|
||||
VCA_API_KEY=${vca_api_key}
|
||||
EOL
|
||||
|
||||
python3 install.py 3 || exit 3
|
||||
|
||||
@@ -14,6 +14,7 @@ apiflash_key = env.str("APIFLASH_KEY")
|
||||
rmbg_key = env.str("RMBG_KEY")
|
||||
vt_key = env.str("VT_KEY")
|
||||
gemini_key = env.str("GEMINI_KEY")
|
||||
vca_api_key = env.str("VCA_API_KEY")
|
||||
|
||||
test_server = env.bool("TEST_SERVER", False)
|
||||
modules_repo_branch = env.str("MODULES_REPO_BRANCH", "master")
|
||||
Reference in New Issue
Block a user