Guest User

Untitled

a guest
Jul 8th, 2023
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. # Main command
  2. @slash_command(name="imagine", description="My second command :)")
  3. @slash_option(
  4. name="prompt",
  5. description="What makes the image",
  6. required=True,
  7. opt_type=OptionType.STRING,
  8. )
  9. @slash_option(
  10. name="steps",
  11. description="Higher doesnt always mean better",
  12. required=True,
  13. opt_type=OptionType.INTEGER
  14. )
  15. async def my_command_function(ctx: SlashContext, prompt: str, steps: int):
  16. if not is_user_allowed(ctx.author_id):
  17. await ctx.send(f"You don't have permission to use this command. Buy it from .superintendent")
  18. return
  19.  
  20. # Send an initial response to the user
  21. initial_message = await ctx.send("Generating your image, please wait...")
  22.  
  23. # Your image generation code here...
  24. my_model = client.Client(
  25. api_key="",
  26. model_key="",
  27. url="https://demo-sd-hf-safetensors-ljpzvwtx39.run.banana.dev",
  28. )
  29.  
  30. inputs = {
  31. "prompt": f"{prompt}",
  32. }
  33.  
  34. result, meta = my_model.call("/", inputs)
  35. base64_image = result['output']
  36. random_num = random.randint(0, 1000)
  37. image_data = base64.b64decode(base64_image)
  38. image_path = f"output_image{random_num}.png"
  39.  
  40. with open(image_path, "wb") as file:
  41. file.write(image_data)
  42.  
  43. print(f"Image file '{image_path}' created successfully.")
  44.  
  45. upload_url = "https://upload.superintendent.me/api/upload"
  46. headers = {
  47. "Authorization": "",
  48. }
  49. files = {"file": open(image_path, "rb")}
  50. response = requests.post(upload_url, headers=headers, files=files)
  51.  
  52. if response.status_code == 200:
  53. upload_response = response.json()
  54. uploaded_files = upload_response.get("files", [])
  55.  
  56. if uploaded_files:
  57. file_url = uploaded_files[0]
  58. try:
  59. print(f"Local image file '{image_path}' deleted successfully.")
  60. except OSError as e:
  61. print(f"Error deleting local image file '{image_path}': {str(e)}")
  62.  
  63. upload_id = file_url.rsplit('/', 1)[-1]
  64. image_url = f"https://upload.superintendent.me/r/{upload_id}"
  65. print("image uploaded")
  66.  
  67. # Edit the initial message with the image URL
  68. await initial_message.edit(content=f"prompt: {prompt} {image_url}")
  69.  
  70. else:
  71. print("File upload failed. No files were uploaded.")
  72. else:
  73. print("File upload failed. Check your authorization credentials.")
  74.  
Add Comment
Please, Sign In to add comment