Spaces:
Running
Running
Upload 2 files
Browse files- .gitattributes +1 -0
- app.py +182 -0
- fine_prompt_sdxl.db +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
fine_prompt_sdxl.db filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sqlite3
|
2 |
+
import streamlit as st
|
3 |
+
import random
|
4 |
+
from typing import List, Dict, Any
|
5 |
+
|
6 |
+
DB_PATH = "fine_prompt_sdxl.db"
|
7 |
+
|
8 |
+
|
9 |
+
def get_db_connection() -> sqlite3.Connection:
|
10 |
+
"""Abre una conexi贸n a la base de datos SQLite."""
|
11 |
+
conn = sqlite3.connect(DB_PATH)
|
12 |
+
conn.row_factory = sqlite3.Row
|
13 |
+
return conn
|
14 |
+
|
15 |
+
|
16 |
+
def load_franchises() -> List[sqlite3.Row]:
|
17 |
+
"""Carga todas las franquicias de la base de datos."""
|
18 |
+
with get_db_connection() as conn:
|
19 |
+
return conn.execute("SELECT * FROM franchises").fetchall()
|
20 |
+
|
21 |
+
|
22 |
+
def load_characters(franchise_id: int) -> List[sqlite3.Row]:
|
23 |
+
"""Carga los personajes asociados a una franquicia."""
|
24 |
+
with get_db_connection() as conn:
|
25 |
+
return conn.execute(
|
26 |
+
"SELECT * FROM characters WHERE franchise_id = ?", (franchise_id,)
|
27 |
+
).fetchall()
|
28 |
+
|
29 |
+
|
30 |
+
def load_categories(tables: List[str]) -> Dict[str, List[str]]:
|
31 |
+
"""Carga las categor铆as de las tablas indicadas."""
|
32 |
+
categories = {}
|
33 |
+
with get_db_connection() as conn:
|
34 |
+
for table in tables:
|
35 |
+
rows = conn.execute(f"SELECT value FROM {table}").fetchall()
|
36 |
+
categories[table] = [row["value"] for row in rows]
|
37 |
+
return categories
|
38 |
+
|
39 |
+
|
40 |
+
def load_special_values(special_tables: List[str]) -> Dict[str, List[str]]:
|
41 |
+
"""Carga los valores especiales de las tablas indicadas."""
|
42 |
+
special_values = {}
|
43 |
+
with get_db_connection() as conn:
|
44 |
+
for table in special_tables:
|
45 |
+
rows = conn.execute(f"SELECT value FROM {table}").fetchall()
|
46 |
+
special_values[table] = [row["value"] for row in rows]
|
47 |
+
return special_values
|
48 |
+
|
49 |
+
|
50 |
+
def sanitize_character_name(name: str) -> str:
|
51 |
+
"""Elimina la parte 'from [franquicia]' del nombre del personaje solo para la lista."""
|
52 |
+
return name.split(" from ")[0].strip() if " from " in name else name
|
53 |
+
|
54 |
+
|
55 |
+
def apply_weight(value: str) -> str:
|
56 |
+
"""Agrega un peso aleatorio entre 0.8 y 1.5 a un elemento."""
|
57 |
+
weight = round(random.uniform(0.8, 1.5), 1)
|
58 |
+
return f"({value}:{weight})"
|
59 |
+
|
60 |
+
|
61 |
+
def generate_prompt(
|
62 |
+
character: Dict[str, Any],
|
63 |
+
categories: Dict[str, List[str]],
|
64 |
+
special_selection: str,
|
65 |
+
special_values: Dict[str, List[str]],
|
66 |
+
) -> str:
|
67 |
+
"""Genera un prompt combinando el personaje, las categor铆as y los valores especiales."""
|
68 |
+
elements = {
|
69 |
+
"hairstyle": apply_weight(random.choice(categories["hairstyle"])),
|
70 |
+
"outfit": apply_weight(random.choice(categories["outfit"])),
|
71 |
+
"scenario": apply_weight(random.choice(categories["scenario"])),
|
72 |
+
"emotion": apply_weight(random.choice(categories["emotion"])),
|
73 |
+
"pose": apply_weight(random.choice(categories["pose"])),
|
74 |
+
"extras": ", ".join(
|
75 |
+
apply_weight(extra) for extra in random.sample(categories["extras"], k=2)
|
76 |
+
),
|
77 |
+
"lighting": apply_weight(random.choice(categories["lighting"])),
|
78 |
+
"distance": apply_weight(random.choice(categories["distance"])),
|
79 |
+
"angle": apply_weight(random.choice(categories["angle"])),
|
80 |
+
"special_elements": apply_weight(random.choice(categories["special_elements"])),
|
81 |
+
"style": apply_weight(random.choice(categories["style"])),
|
82 |
+
}
|
83 |
+
|
84 |
+
special_section = ""
|
85 |
+
if special_selection in ("special_all", "special_s_e", "both"):
|
86 |
+
special_section = "(nsfw:1.5), "
|
87 |
+
if special_selection == "both":
|
88 |
+
special_all_values = random.sample(special_values.get("special_all", []), 2)
|
89 |
+
special_se_values = random.sample(special_values.get("special_s_e", []), 1)
|
90 |
+
all_special_values = special_all_values + special_se_values
|
91 |
+
special_section += (
|
92 |
+
", ".join(apply_weight(value) for value in all_special_values) + ", "
|
93 |
+
) # esto sirve para
|
94 |
+
else:
|
95 |
+
values = special_values.get(
|
96 |
+
"special_all" if special_selection == "special_all" else "special_s_e",
|
97 |
+
[],
|
98 |
+
)
|
99 |
+
selected_values = random.sample(values, 2)
|
100 |
+
special_section += (
|
101 |
+
", ".join(apply_weight(value) for value in selected_values) + ", "
|
102 |
+
)
|
103 |
+
|
104 |
+
core_tags = character["core_tags"] if "core_tags" in character.keys() else ""
|
105 |
+
core_tags = random.choice(
|
106 |
+
[tag.strip() for tag in core_tags.split(";") if tag.strip()]
|
107 |
+
)
|
108 |
+
core_tags_section = f"{core_tags}, " if core_tags else ""
|
109 |
+
prompt = (
|
110 |
+
f"{character['name']}, {core_tags_section}"
|
111 |
+
f"{elements['hairstyle']}, wearing {elements['outfit']}, positioned in a {elements['scenario']}, "
|
112 |
+
f"striking a pose of {elements['pose']}, feeling {elements['emotion']}. "
|
113 |
+
f"Scene elements include {elements['extras']}, {special_section}"
|
114 |
+
f"{elements['angle']}, {elements['distance']}, {elements['lighting']}, "
|
115 |
+
f"{elements['special_elements']}, "
|
116 |
+
"masterpiece, high score, great score, absurdres, best quality, highres"
|
117 |
+
)
|
118 |
+
return prompt
|
119 |
+
|
120 |
+
|
121 |
+
st.title("Prompt Generator")
|
122 |
+
|
123 |
+
franchises = load_franchises()
|
124 |
+
franchise_name_to_id = {franchise["name"]: franchise["id"] for franchise in franchises}
|
125 |
+
selected_franchise = st.selectbox(
|
126 |
+
"Select a franchise:", list(franchise_name_to_id.keys())
|
127 |
+
)
|
128 |
+
selected_franchise_id = franchise_name_to_id[selected_franchise]
|
129 |
+
|
130 |
+
characters = load_characters(selected_franchise_id)
|
131 |
+
|
132 |
+
character_name_to_data = {
|
133 |
+
sanitize_character_name(character["name"]): character for character in characters
|
134 |
+
}
|
135 |
+
|
136 |
+
selected_character_name = st.selectbox(
|
137 |
+
"Select a character:", list(character_name_to_data.keys())
|
138 |
+
)
|
139 |
+
|
140 |
+
selected_character = character_name_to_data[selected_character_name]
|
141 |
+
|
142 |
+
|
143 |
+
status_color_map = {
|
144 |
+
"recognized": "green",
|
145 |
+
"partial": "yellow",
|
146 |
+
"not recognized": "red",
|
147 |
+
}
|
148 |
+
character_status = (
|
149 |
+
selected_character["status"] if "status" in selected_character.keys() else "unknown"
|
150 |
+
)
|
151 |
+
status_color = status_color_map.get(character_status, "gray")
|
152 |
+
st.markdown(
|
153 |
+
f"<p style='color: {status_color}; font-size: 16px;'>Status: {character_status.capitalize()}</p>",
|
154 |
+
unsafe_allow_html=True,
|
155 |
+
)
|
156 |
+
|
157 |
+
special_selection = st.radio(
|
158 |
+
"Include special categories:", ["none", "special_all", "special_s_e", "both"]
|
159 |
+
)
|
160 |
+
|
161 |
+
if st.button("Generate Prompt"):
|
162 |
+
tables = [
|
163 |
+
"hairstyle",
|
164 |
+
"outfit",
|
165 |
+
"scenario",
|
166 |
+
"emotion",
|
167 |
+
"pose",
|
168 |
+
"extras",
|
169 |
+
"lighting",
|
170 |
+
"distance",
|
171 |
+
"angle",
|
172 |
+
"special_elements",
|
173 |
+
"style",
|
174 |
+
]
|
175 |
+
categories = load_categories(tables)
|
176 |
+
special_values = {}
|
177 |
+
if special_selection in ("special_all", "special_s_e", "both"):
|
178 |
+
special_values = load_special_values(["special_all", "special_s_e"])
|
179 |
+
prompt = generate_prompt(
|
180 |
+
selected_character, categories, special_selection, special_values
|
181 |
+
)
|
182 |
+
st.code(prompt, language="python", wrap_lines=True)
|
fine_prompt_sdxl.db
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ecd94be02c1bbbf40512b2d29692c5b279e262e13ca8ce95b1be321e0bd7618c
|
3 |
+
size 22085632
|