Prodia.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. from __future__ import annotations
  2. from aiohttp import ClientSession
  3. import asyncio
  4. from ..typing import AsyncResult, Messages
  5. from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
  6. from ..image import ImageResponse
  7. class Prodia(AsyncGeneratorProvider, ProviderModelMixin):
  8. url = "https://app.prodia.com"
  9. api_endpoint = "https://api.prodia.com/generate"
  10. working = True
  11. default_model = 'absolutereality_v181.safetensors [3d9d4d2b]'
  12. image_models = [
  13. '3Guofeng3_v34.safetensors [50f420de]',
  14. 'absolutereality_V16.safetensors [37db0fc3]',
  15. default_model,
  16. 'amIReal_V41.safetensors [0a8a2e61]',
  17. 'analog-diffusion-1.0.ckpt [9ca13f02]',
  18. 'aniverse_v30.safetensors [579e6f85]',
  19. 'anythingv3_0-pruned.ckpt [2700c435]',
  20. 'anything-v4.5-pruned.ckpt [65745d25]',
  21. 'anythingV5_PrtRE.safetensors [893e49b9]',
  22. 'AOM3A3_orangemixs.safetensors [9600da17]',
  23. 'blazing_drive_v10g.safetensors [ca1c1eab]',
  24. 'breakdomain_I2428.safetensors [43cc7d2f]',
  25. 'breakdomain_M2150.safetensors [15f7afca]',
  26. 'cetusMix_Version35.safetensors [de2f2560]',
  27. 'childrensStories_v13D.safetensors [9dfaabcb]',
  28. 'childrensStories_v1SemiReal.safetensors [a1c56dbb]',
  29. 'childrensStories_v1ToonAnime.safetensors [2ec7b88b]',
  30. 'Counterfeit_v30.safetensors [9e2a8f19]',
  31. 'cuteyukimixAdorable_midchapter3.safetensors [04bdffe6]',
  32. 'cyberrealistic_v33.safetensors [82b0d085]',
  33. 'dalcefo_v4.safetensors [425952fe]',
  34. 'deliberate_v2.safetensors [10ec4b29]',
  35. 'deliberate_v3.safetensors [afd9d2d4]',
  36. 'dreamlike-anime-1.0.safetensors [4520e090]',
  37. 'dreamlike-diffusion-1.0.safetensors [5c9fd6e0]',
  38. 'dreamlike-photoreal-2.0.safetensors [fdcf65e7]',
  39. 'dreamshaper_6BakedVae.safetensors [114c8abb]',
  40. 'dreamshaper_7.safetensors [5cf5ae06]',
  41. 'dreamshaper_8.safetensors [9d40847d]',
  42. 'edgeOfRealism_eorV20.safetensors [3ed5de15]',
  43. 'EimisAnimeDiffusion_V1.ckpt [4f828a15]',
  44. 'elldreths-vivid-mix.safetensors [342d9d26]',
  45. 'epicphotogasm_xPlusPlus.safetensors [1a8f6d35]',
  46. 'epicrealism_naturalSinRC1VAE.safetensors [90a4c676]',
  47. 'epicrealism_pureEvolutionV3.safetensors [42c8440c]',
  48. 'ICantBelieveItsNotPhotography_seco.safetensors [4e7a3dfd]',
  49. 'indigoFurryMix_v75Hybrid.safetensors [91208cbb]',
  50. 'juggernaut_aftermath.safetensors [5e20c455]',
  51. 'lofi_v4.safetensors [ccc204d6]',
  52. 'lyriel_v16.safetensors [68fceea2]',
  53. 'majicmixRealistic_v4.safetensors [29d0de58]',
  54. 'mechamix_v10.safetensors [ee685731]',
  55. 'meinamix_meinaV9.safetensors [2ec66ab0]',
  56. 'meinamix_meinaV11.safetensors [b56ce717]',
  57. 'neverendingDream_v122.safetensors [f964ceeb]',
  58. 'openjourney_V4.ckpt [ca2f377f]',
  59. 'pastelMixStylizedAnime_pruned_fp16.safetensors [793a26e8]',
  60. 'portraitplus_V1.0.safetensors [1400e684]',
  61. 'protogenx34.safetensors [5896f8d5]',
  62. 'Realistic_Vision_V1.4-pruned-fp16.safetensors [8d21810b]',
  63. 'Realistic_Vision_V2.0.safetensors [79587710]',
  64. 'Realistic_Vision_V4.0.safetensors [29a7afaa]',
  65. 'Realistic_Vision_V5.0.safetensors [614d1063]',
  66. 'Realistic_Vision_V5.1.safetensors [a0f13c83]',
  67. 'redshift_diffusion-V10.safetensors [1400e684]',
  68. 'revAnimated_v122.safetensors [3f4fefd9]',
  69. 'rundiffusionFX25D_v10.safetensors [cd12b0ee]',
  70. 'rundiffusionFX_v10.safetensors [cd4e694d]',
  71. 'sdv1_4.ckpt [7460a6fa]',
  72. 'v1-5-pruned-emaonly.safetensors [d7049739]',
  73. 'v1-5-inpainting.safetensors [21c7ab71]',
  74. 'shoninsBeautiful_v10.safetensors [25d8c546]',
  75. 'theallys-mix-ii-churned.safetensors [5d9225a4]',
  76. 'timeless-1.0.ckpt [7c4971d4]',
  77. 'toonyou_beta6.safetensors [980f6b15]',
  78. ]
  79. models = [*image_models]
  80. @classmethod
  81. def get_model(cls, model: str) -> str:
  82. if model in cls.models:
  83. return model
  84. elif model in cls.model_aliases:
  85. return cls.model_aliases[model]
  86. else:
  87. return cls.default_model
  88. @classmethod
  89. async def create_async_generator(
  90. cls,
  91. model: str,
  92. messages: Messages,
  93. proxy: str = None,
  94. negative_prompt: str = "",
  95. steps: str = 20, # 1-25
  96. cfg: str = 7, # 0-20
  97. seed: str = "-1",
  98. sampler: str = "DPM++ 2M Karras", # "Euler", "Euler a", "Heun", "DPM++ 2M Karras", "DPM++ SDE Karras", "DDIM"
  99. aspect_ratio: str = "square", # "square", "portrait", "landscape"
  100. **kwargs
  101. ) -> AsyncResult:
  102. model = cls.get_model(model)
  103. headers = {
  104. "accept": "*/*",
  105. "accept-language": "en-US,en;q=0.9",
  106. "origin": cls.url,
  107. "referer": f"{cls.url}/",
  108. "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
  109. }
  110. async with ClientSession(headers=headers) as session:
  111. prompt = messages[-1]['content'] if messages else ""
  112. params = {
  113. "new": "true",
  114. "prompt": prompt,
  115. "model": model,
  116. "negative_prompt": negative_prompt,
  117. "steps": steps,
  118. "cfg": cfg,
  119. "seed": seed,
  120. "sampler": sampler,
  121. "aspect_ratio": aspect_ratio
  122. }
  123. async with session.get(cls.api_endpoint, params=params, proxy=proxy) as response:
  124. response.raise_for_status()
  125. job_data = await response.json()
  126. job_id = job_data["job"]
  127. image_url = await cls._poll_job(session, job_id, proxy)
  128. yield ImageResponse(image_url, alt=prompt)
  129. @classmethod
  130. async def _poll_job(cls, session: ClientSession, job_id: str, proxy: str, max_attempts: int = 30, delay: int = 2) -> str:
  131. for _ in range(max_attempts):
  132. async with session.get(f"https://api.prodia.com/job/{job_id}", proxy=proxy) as response:
  133. response.raise_for_status()
  134. job_status = await response.json()
  135. if job_status["status"] == "succeeded":
  136. return f"https://images.prodia.xyz/{job_id}.png"
  137. elif job_status["status"] == "failed":
  138. raise Exception("Image generation failed")
  139. await asyncio.sleep(delay)
  140. raise Exception("Timeout waiting for image generation")