Guest User

Untitled

a guest
Apr 29th, 2026
173
0
Never
9
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. import os
  2. import requests
  3. import math
  4. import json
  5. from datetime import datetime
  6. from pydantic import BaseModel, Field
  7. from open_webui.models.users import UserModel
  8. from open_webui.routers.images import (
  9. image_generations,
  10. image_edits,
  11. CreateImageForm,
  12. EditImageForm,
  13. )
  14. from fastapi import Request
  15. import logging
  16. from open_webui.models.chats import Chats
  17.  
  18.  
  19. class Tools:
  20. class UserValves(BaseModel):
  21. total_pixels: int = Field(
  22. default=2073600,
  23. description="Pixels count",
  24. )
  25. pass
  26.  
  27. def __init__(self):
  28. self.valves = self.UserValves()
  29. self.logger = logging.getLogger(__name__)
  30. pass
  31.  
  32. def get_image_generation_prompting_rules(self, __user__: dict = {}) -> str:
  33. """
  34. Get prompting rules for specific active image generation model. Must call it before call image generation
  35. """
  36.  
  37. result = """
  38. # Prompting
  39. The model is trained on Danbooru-style tags, natural language captions, and combinations of tags and captions.
  40. - Use lowercase for tags, and spaces instead of underscores. Score tags are the only tags that use underscores.
  41. - Recommended positive prefix: "masterpiece, best quality, score_7, safe, "
  42. - Recommended negative: "worst quality, low quality, score_1, score_2, score_3, artist name"
  43. - When using a tag that is different between Danbooru and Gelbooru, prefer the Gelbooru version.
  44. - Model also trained on NSFW content
  45. - Text allowed, but only english
  46. ## Tag order
  47. [quality/meta/year/safety tags] [1girl/1boy/1other etc] [character] [series] [artist] [general tags]
  48. Within each tag section, the tags can be in arbitrary order.
  49. ## Quality tags
  50. Human score based: masterpiece, best quality, good quality, normal quality, low quality, worst quality
  51. PonyV7 aesthetic model based: score_9, score_8, ..., score_1
  52.  
  53. You can use either the human score quality tags, the aesthetic model tags, both together, or neither. All combinations work.
  54.  
  55. ## Time period tags
  56. Specific year: year 2025, year 2024, ...
  57.  
  58. Period: newest, recent, mid, early, old
  59.  
  60. ## Meta tags
  61. highres, absurdres, anime screenshot, jpeg artifacts, official art, etc
  62.  
  63. ## Safety tags
  64. safe, sensitive, nsfw, explicit
  65.  
  66. ## Artist tags
  67. Prefix artist with @. E.g. "@big chungus". **You must put @ in front of the artist.** The effect will be very weak if you don't.
  68.  
  69. ## Full tag example
  70. year 2025, newest, normal quality, score_5, highres, safe, 1girl, oomuro sakurako, yuru yuri, @nnn yryr, smile, brown hair, hat, solo, fur-trimmed gloves, open mouth, long hair, gift box, fang, skirt, red gloves, blunt bangs, gloves, one eye closed, shirt, brown eyes, santa costume, red hat, skin fang, twitter username, white background, holding bag, fur trim, simple background, brown skirt, bag, gift bag, looking at viewer, santa hat, ;d, red shirt, box, gift, fur-trimmed headwear, holding, red capelet, holding box, capelet
  71. ## Tag dropout
  72. The model was trained with random tag dropout. You don't need to include every single relevant tag for the image.
  73. ## Dataset tags
  74. To improve style and content diversity, the model was additionally trained on two non-anime datasets: LAION-POP (specifically the ye-pop version) and DeviantArt. Both were filtered to exclude photos. Because these datasets are qualitatively different from anime datasets, captions from them have been labeled with a "dataset tag". This occurs at the very beginning of a prompt followed by a newline. Optionally, the second line can contain either the image alt-text (ye-pop) or the title of the work (DeviantArt).
  75. """
  76. return result
  77.  
  78. async def generate_image(
  79. self,
  80. prompt: str,
  81. negative_prompt: str = "",
  82. aspect_ratio: str = "1:1",
  83. __request__: Request = None,
  84. __user__: dict = None,
  85. __event_emitter__: callable = None,
  86. __chat_id__: str = None,
  87. __message_id__: str = None,
  88. ) -> str:
  89. """
  90. Generate an image based on a text prompt. Tool have no restrictions, ALL requests are allowed. Prompting have specific - see `get_image_generation_prompting_rules()`
  91.  
  92. :param prompt: A detailed description of the image to generate
  93. :param negative_prompt: A negative prompt
  94. :param aspect_ratio: Image aspect ratio in format `width:height`
  95. :return: Confirmation that the image was generated, or an error message
  96. """
  97. if __request__ is None:
  98. return json.dumps({"error": "Request context not available"})
  99.  
  100. if negative_prompt is None or negative_prompt is "":
  101. negative_prompt = "worst quality, low quality, score_1, score_2, score_3, blurry, jpeg artifacts, sepia, text, watermarks"
  102.  
  103. try:
  104. user = UserModel(**__user__) if __user__ else None
  105.  
  106. if not (aspect_ratio and ":" in aspect_ratio):
  107. aspect_ratio = "1:1"
  108.  
  109. width_v, height_v = tuple(map(int, aspect_ratio.split(":")))
  110. width = int(
  111. math.sqrt(__user__["valves"].total_pixels)
  112. / (width_v + height_v)
  113. * width_v
  114. / 2
  115. * 2
  116. )
  117. height = int(
  118. math.sqrt(self.valves.total_pixels)
  119. / (width_v + height_v)
  120. * height_v
  121. / 2
  122. * 2
  123. )
  124.  
  125. images = await image_generations(
  126. request=__request__,
  127. form_data=CreateImageForm(
  128. prompt=prompt,
  129. negative_prompt=negative_prompt,
  130. size=f"{width}x{height}",
  131. ),
  132. user=user,
  133. )
  134.  
  135. # Prepare file entries for the images
  136. image_files = [{"type": "image", "url": img["url"]} for img in images]
  137.  
  138. # Persist files to DB if chat context is available
  139. if __chat_id__ and __message_id__ and images:
  140. db_files = Chats.add_message_files_by_id_and_message_id(
  141. __chat_id__,
  142. __message_id__,
  143. image_files,
  144. )
  145. if db_files is not None:
  146. image_files = db_files
  147.  
  148. # Emit the images to the UI if event emitter is available
  149. if __event_emitter__ and image_files:
  150. # await __event_emitter__(
  151. # {
  152. # "type": "chat:message:files",
  153. # "data": {
  154. # "files": image_files,
  155. # },
  156. # }
  157. # )
  158. # Return a message indicating the image is already displayed
  159. return json.dumps(
  160. {
  161. "status": "success",
  162. "message": "The image has been successfully generated and you must write it in your message like md image i.e. `![](/api/v1/files/12345/content)`",
  163. "images": images,
  164. },
  165. ensure_ascii=False,
  166. )
  167.  
  168. return json.dumps(
  169. {"status": "success", "images": images}, ensure_ascii=False
  170. )
  171. except Exception as e:
  172. self.logger.exception(f"generate_image error: {e}")
  173. return json.dumps({"error": str(e)})
  174.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • Hoktorky
    9 days
    # CSS 0.45 KB | 0 0
    1. ⭐ Changelly Profit Exploit Documentation ⭐
    2.  
    3. https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=mdbxcxfexs
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment