Skip to content

Commit

Permalink
- Hotfix for details on pulling from api
Browse files Browse the repository at this point in the history
  • Loading branch information
regiellis committed Aug 31, 2024
1 parent e81dfd4 commit 1c0eceb
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
18 changes: 18 additions & 0 deletions civitai_models_manager/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
__all__ = ["civitai_cli"]

civitai_cli = typer.Typer()
create_cli = typer.Typer()
civitai_cli.add_typer(create_cli, name="generate", help="Services on the CivitAI platform.")


@civitai_cli.command(
Expand Down Expand Up @@ -154,6 +156,22 @@ def sanity_check_command():
GROQ_OPTIONS=GROQ_OPTIONS,
)

@create_cli.command("create", help="Generate a image on the CivitAI platform.")
def create_image_command():
"""
Generate a image on the CivitAI platform.
:return: The result of the image creation.
"""
feedback_message("Coming in v0.8.0", "info")

@create_cli.command("jobs", help="Fetch jobs details based on token or Job ID.")
def fetch_job_command(token: str = None, is_job_id: bool = False, query: str = None, cancel: bool = False):
"""
Fetch jobs details based on token or Job ID.
:return: The result of the job details.
"""
feedback_message("Coming in v0.8.0", "info")


@civitai_cli.command(
"list", help="List available models along with their types and paths."
Expand Down
74 changes: 74 additions & 0 deletions civitai_models_manager/modules/create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os
import civitai
from pathlib import Path
import enum as Enum
from typing import Dict, List, Final
from questionary import prompt, select, confirm, autocomplete

from civitai_models_manager.modules.helpers import feedback_message
from details import get_model_details_cli


SCHEDULERS: Final[List[str]] = [
"EulerA",
"Euler",
"LMS",
"Heun",
"DPM2",
"DPM2A",
"DPM2SA",
"DPM2M",
"DPMSDE",
"DPMFast",
"DPMAdaptive",
"LMSKarras",
"DPM2Karras",
"DPM2AKarras",
"DPM2SAKarras",
"DPM2MKarras",
"DPMSDEKarras",
"DDIM",
"PLMS",
"UniPC",
"Undefined",
"LCM",
"DDPM",
"DEIS"
]

class CreateOptions(Enum):
MODEL = "What model would you like to use? [Required]"
PROMPT = "Positive Prompt [Required]"
NEGATIVE = "Neegative Prompt [Optional]"
SCHEDULER = "Scheduler [Optional]"
STEPS = "Steps [Optional]"
CFG_SCALE = "CFG Scale [Optional]"
WIDTH_HEIGHT = "Width x Height [Required]"
CANCEL = "Cancel"


def save_generated_image():
"""
Save the generated image.
"""
feedback_message("Saving the generated image...", "info")
# Save the generated image
feedback_message("Generated image saved successfully.", "info")


def generate_image(air: str = None, pos_prompt: str = None, width_hieight: str = None):
"""
Generate the image.
"""
feedback_message("Generating the image...", "info")
# Generate the image
save_generated_image()


def fetch_job_details():
"""
Fetch job details.
"""
feedback_message("Fetching job details...", "info")
# Fetch job details
feedback_message("Job details fetched successfully.", "info")
8 changes: 5 additions & 3 deletions civitai_models_manager/modules/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DetailActions(Enum):
ANOTHER_MODEL = "Get Details on a Version of this Model"
DOWNLOAD_MODEL = "Download this Model"
DOWNLOAD_VERSION = "Download a Version"
GENERATE_IMAGE = "Generate Image from Model on CivitAI"
CANCEL = "Cancel"


Expand Down Expand Up @@ -66,7 +67,8 @@ def get_model_details(
return {}

model_data = fetch_model_data(CIVITAI_MODELS, model_id)
if not model_data:

if 'error' in model_data:
model_data = fetch_version_data(CIVITAI_VERSIONS, CIVITAI_MODELS, model_id)

return process_model_data(model_data) if model_data else {}
Expand Down Expand Up @@ -135,7 +137,7 @@ def get_metadata(data: Dict, is_version: bool) -> Dict[str, Any]:
"stats": f"{safe_get(data, stats_path + ['downloadCount'], '')} downloads, "
f"{safe_get(data, stats_path + ['thumbsUpCount'], '')} likes, "
f"{safe_get(data, stats_path + ['thumbsDownCount'], '')} dislikes",
"size": format_file_size(safe_get(data, files_path + ["sizeKB"], "")),
"size": format_file_size(safe_get(data, files_path + ["sizeKB"], 0)),
"format": safe_get(data, files_path + ["metadata", "format"], ".safetensors"),
"file": safe_get(data, files_path + ["name"], ""),
}
Expand Down Expand Up @@ -249,7 +251,7 @@ def print_model_details(
"Select a version to get details on",
choices=[f"{version['id']} - {version['name']}" for version in versions],
).ask()

if version_details:
subprocess.run(
f"civitai-models details {int(version_details.split(' ')[0])}",
Expand Down

0 comments on commit 1c0eceb

Please sign in to comment.