Update Modules/Generate_Image.py
Browse files- Modules/Generate_Image.py +10 -3
Modules/Generate_Image.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import os
|
|
|
|
| 4 |
import random
|
| 5 |
from typing import Annotated
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
from PIL import Image
|
| 9 |
from huggingface_hub import InferenceClient
|
|
|
|
| 10 |
|
| 11 |
from app import _log_call_end, _log_call_start, _truncate_for_log
|
| 12 |
from ._docstrings import autodoc
|
|
@@ -38,7 +40,7 @@ def Generate_Image(
|
|
| 38 |
width: Annotated[int, "Output width in pixels (64–1216, multiple of 32 recommended)."] = 1024,
|
| 39 |
height: Annotated[int, "Output height in pixels (64–1216, multiple of 32 recommended)."] = 1024,
|
| 40 |
sampler: Annotated[str, "Sampling method label (UI only). Common options: 'DPM++ 2M Karras', 'DPM++ SDE Karras', 'Euler', 'Euler a', 'Heun', 'DDIM'."] = "DPM++ 2M Karras",
|
| 41 |
-
) ->
|
| 42 |
_log_call_start(
|
| 43 |
"Generate_Image",
|
| 44 |
prompt=_truncate_for_log(prompt, 200),
|
|
@@ -67,8 +69,13 @@ def Generate_Image(
|
|
| 67 |
guidance_scale=cfg_scale,
|
| 68 |
seed=seed if seed != -1 else random.randint(1, 1_000_000_000),
|
| 69 |
)
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
except Exception as exc: # pylint: disable=broad-except
|
| 73 |
last_error = exc
|
| 74 |
continue
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import os
|
| 4 |
+
import uuid
|
| 5 |
import random
|
| 6 |
from typing import Annotated
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
from PIL import Image
|
| 10 |
from huggingface_hub import InferenceClient
|
| 11 |
+
from .File_System import ROOT_DIR
|
| 12 |
|
| 13 |
from app import _log_call_end, _log_call_start, _truncate_for_log
|
| 14 |
from ._docstrings import autodoc
|
|
|
|
| 40 |
width: Annotated[int, "Output width in pixels (64–1216, multiple of 32 recommended)."] = 1024,
|
| 41 |
height: Annotated[int, "Output height in pixels (64–1216, multiple of 32 recommended)."] = 1024,
|
| 42 |
sampler: Annotated[str, "Sampling method label (UI only). Common options: 'DPM++ 2M Karras', 'DPM++ SDE Karras', 'Euler', 'Euler a', 'Heun', 'DDIM'."] = "DPM++ 2M Karras",
|
| 43 |
+
) -> str:
|
| 44 |
_log_call_start(
|
| 45 |
"Generate_Image",
|
| 46 |
prompt=_truncate_for_log(prompt, 200),
|
|
|
|
| 69 |
guidance_scale=cfg_scale,
|
| 70 |
seed=seed if seed != -1 else random.randint(1, 1_000_000_000),
|
| 71 |
)
|
| 72 |
+
|
| 73 |
+
filename = f"image_{uuid.uuid4().hex[:8]}.png"
|
| 74 |
+
output_path = os.path.join(ROOT_DIR, filename)
|
| 75 |
+
image.save(output_path)
|
| 76 |
+
|
| 77 |
+
_log_call_end("Generate_Image", f"provider={provider} size={image.size} saved_to={filename}")
|
| 78 |
+
return output_path
|
| 79 |
except Exception as exc: # pylint: disable=broad-except
|
| 80 |
last_error = exc
|
| 81 |
continue
|