![]() |
#1 |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Jul 2023
Device: k4
|
webp support oder other option to load generated image
I want to generate an image with stablediffusion (this works on my kindle) and load and show it with fbink (both works with other Pictures). But the generated picture doesent work, i guess because stablediff. give webp-format back. Its hard to install anything on the kindle (webp-lib ...). Any suggestions? Thanks!
UserWarning: image file could not be identified because WEBP support not installed The Error:UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file for this command: Image.open Here the code: Code:
import requests import os import base64 import time from PIL import Image horde_api_key = "..." class RequestData(object): def __init__(self): self.client_agent = "cli_request.py:1.1.0:(discord)db0#1625" self.api_key = horde_api_key self.filename = "test2.webp" self.imgen_params = { "n": 1, "width": 384, "height":512, "steps": 50, "sampler_name": "k_euler", "cfg_scale": 7.5, "denoising_strength": 0.6, } self.submit_dict = { "prompt":"Forrest", "api_key": horde_api_key, "nsfw": False, "censor_nsfw": False, "trusted_workers": False, "models": ["stable_diffusion"], "r2": True } self.source_image = None self.source_processing = "img2img" self.source_mask = None def get_submit_dict(self): submit_dict = self.submit_dict.copy() submit_dict["params"] = self.imgen_params submit_dict["source_processing"] = self.source_processing return submit_dict def generate(): request_data = RequestData() headers = { "apikey": request_data.api_key, "Client-Agent": request_data.client_agent, } submit_req = requests.post(f'https://stablehorde.net/api/v2/generate/async', json=request_data.get_submit_dict(), headers=headers) if submit_req.ok: submit_results = submit_req.json() req_id = submit_results['id'] is_done = False while not is_done: chk_req = requests.get(f'https://stablehorde.net/api/v2/generate/check/{req_id}') if not chk_req.ok: print(chk_req.text) return chk_results = chk_req.json() is_done = chk_results['done'] time.sleep(0.8) retrieve_req = requests.get(f'https://stablehorde.net/api/v2/generate/status/{req_id}') if not retrieve_req.ok: print(retrieve_req.text) return results_json = retrieve_req.json() if results_json['faulted']: print("Something went wrong when generating the request.") return results = results_json['generations'] for iter in range(len(results)): final_filename = request_data.filename if len(results) > 1: final_filename = f"{iter}_{request_data.filename}" img_data = requests.get(results[iter]["img"]).content with open(final_filename, 'wb') as f: f.write(img_data) # Ensure the file is fully written and closed before opening as an image with open(final_filename, 'rb') as f: imgg = Image.open(f) # test writing with other format imgg.save('test2a.png') return final_filename else: print(submit_req.text) def main(): image_file = generate() if image_file: print(f"Image saved as {image_file}") else: print("Failed to generate image.") if __name__ == "__main__": main() |
![]() |
![]() |
![]() |
#2 |
BLAM!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
Nope, I don't build IM with webp support.
That might change for the next rebuild, if I don't forget about it ;o). |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Jul 2023
Device: k4
|
Thanks. So is there maybe an other way? For example a webservice to convert online reachable over kindle-linux, so the limited kindle linux have not to do it? Thanks!
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
No 'Load Plugin from File' option on Calibre 6.4? | fre1102 | Plugins | 2 | 09-11-2022 03:23 PM |
webp image handling | Turtle91 | Sigil | 4 | 08-28-2022 03:41 PM |
Kindle Previewer doesn't support Calibre generated azw3/mobi | xtraktor | Calibre | 3 | 02-12-2021 09:04 AM |
Image header on the actual auto-TOC generated page? | Muckraker | Calibre | 1 | 06-05-2011 10:57 AM |