Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Main command
- @slash_command(name="imagine", description="My second command :)")
- @slash_option(
- name="prompt",
- description="What makes the image",
- required=True,
- opt_type=OptionType.STRING,
- )
- @slash_option(
- name="steps",
- description="Higher doesnt always mean better",
- required=True,
- opt_type=OptionType.INTEGER
- )
- async def my_command_function(ctx: SlashContext, prompt: str, steps: int):
- if not is_user_allowed(ctx.author_id):
- await ctx.send(f"You don't have permission to use this command. Buy it from .superintendent")
- return
- # Send an initial response to the user
- initial_message = await ctx.send("Generating your image, please wait...")
- # Your image generation code here...
- my_model = client.Client(
- api_key="",
- model_key="",
- url="https://demo-sd-hf-safetensors-ljpzvwtx39.run.banana.dev",
- )
- inputs = {
- "prompt": f"{prompt}",
- }
- result, meta = my_model.call("/", inputs)
- base64_image = result['output']
- random_num = random.randint(0, 1000)
- image_data = base64.b64decode(base64_image)
- image_path = f"output_image{random_num}.png"
- with open(image_path, "wb") as file:
- file.write(image_data)
- print(f"Image file '{image_path}' created successfully.")
- upload_url = "https://upload.superintendent.me/api/upload"
- headers = {
- "Authorization": "",
- }
- files = {"file": open(image_path, "rb")}
- response = requests.post(upload_url, headers=headers, files=files)
- if response.status_code == 200:
- upload_response = response.json()
- uploaded_files = upload_response.get("files", [])
- if uploaded_files:
- file_url = uploaded_files[0]
- try:
- print(f"Local image file '{image_path}' deleted successfully.")
- except OSError as e:
- print(f"Error deleting local image file '{image_path}': {str(e)}")
- upload_id = file_url.rsplit('/', 1)[-1]
- image_url = f"https://upload.superintendent.me/r/{upload_id}"
- print("image uploaded")
- # Edit the initial message with the image URL
- await initial_message.edit(content=f"prompt: {prompt} {image_url}")
- else:
- print("File upload failed. No files were uploaded.")
- else:
- print("File upload failed. Check your authorization credentials.")
Add Comment
Please, Sign In to add comment