|
1 | 1 | from __future__ import annotations
|
2 | 2 | import math
|
3 | 3 | import os
|
| 4 | +import sys |
| 5 | +import traceback |
4 | 6 |
|
5 | 7 | import numpy as np
|
6 | 8 | from PIL import Image
|
|
12 | 14 | from functools import partial
|
13 | 15 | from dataclasses import dataclass
|
14 | 16 |
|
15 |
| -from modules import processing, shared, images, devices, sd_models |
| 17 | +from modules import processing, shared, images, devices, sd_models, sd_samplers |
16 | 18 | from modules.shared import opts
|
17 | 19 | import modules.gfpgan_model
|
18 | 20 | from modules.ui import plaintext_to_html
|
|
22 | 24 | import gradio as gr
|
23 | 25 | import safetensors.torch
|
24 | 26 |
|
25 |
| - |
26 | 27 | class LruCache(OrderedDict):
|
27 | 28 | @dataclass(frozen=True)
|
28 | 29 | class Key:
|
@@ -214,39 +215,8 @@ def run_pnginfo(image):
|
214 | 215 | if image is None:
|
215 | 216 | return '', '', ''
|
216 | 217 |
|
217 |
| - items = image.info |
218 |
| - geninfo = '' |
219 |
| - |
220 |
| - if "exif" in image.info: |
221 |
| - exif = piexif.load(image.info["exif"]) |
222 |
| - exif_comment = (exif or {}).get("Exif", {}).get(piexif.ExifIFD.UserComment, b'') |
223 |
| - try: |
224 |
| - exif_comment = piexif.helper.UserComment.load(exif_comment) |
225 |
| - except ValueError: |
226 |
| - exif_comment = exif_comment.decode('utf8', errors="ignore") |
227 |
| - |
228 |
| - items['exif comment'] = exif_comment |
229 |
| - geninfo = exif_comment |
230 |
| - |
231 |
| - for field in ['jfif', 'jfif_version', 'jfif_unit', 'jfif_density', 'dpi', 'exif', |
232 |
| - 'loop', 'background', 'timestamp', 'duration']: |
233 |
| - items.pop(field, None) |
234 |
| - |
235 |
| - geninfo = items.get('parameters', geninfo) |
236 |
| - |
237 |
| - # nai prompt |
238 |
| - if "Software" in items.keys() and items["Software"] == "NovelAI": |
239 |
| - import json |
240 |
| - json_info = json.loads(items["Comment"]) |
241 |
| - geninfo = f'{items["Description"]}\r\nNegative prompt: {json_info["uc"]}\r\n' |
242 |
| - sampler = "Euler a" |
243 |
| - if json_info["sampler"] == "k_euler_ancestral": |
244 |
| - sampler = "Euler a" |
245 |
| - elif json_info["sampler"] == "k_euler": |
246 |
| - sampler = "Euler" |
247 |
| - model_hash = '925997e9' # assuming this is the correct model hash |
248 |
| - # not sure with noise and strength parameter |
249 |
| - geninfo += f'Steps: {json_info["steps"]}, Sampler: {sampler}, CFG scale: {json_info["scale"]}, Seed: {json_info["seed"]}, Size: {image.width}x{image.height}, Model hash: {model_hash}' # , Denoising strength: {json_info["noise"]}' |
| 218 | + geninfo, items = images.read_info_from_image(image) |
| 219 | + items = {**{'parameters': geninfo}, **items} |
250 | 220 |
|
251 | 221 | info = ''
|
252 | 222 | for key, text in items.items():
|
|
0 commit comments