Update app.py
Browse files
app.py
CHANGED
@@ -11,16 +11,17 @@ with open('style.css') as f:
|
|
11 |
text_client = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.1")
|
12 |
image_client = Client("Boboiazumi/animagine-xl-3.1")
|
13 |
|
14 |
-
def format_prompt_for_description(name, hair_color,
|
15 |
-
prompt = f"Create a waifu character named {name} with {hair_color} hair,
|
16 |
-
prompt += f"
|
17 |
-
|
18 |
-
|
19 |
return prompt
|
20 |
|
21 |
-
def format_prompt_for_image(name, hair_color,
|
22 |
-
prompt = f"Generate an image prompt for a waifu character named {name} with {hair_color} hair,
|
23 |
-
|
|
|
24 |
return prompt
|
25 |
|
26 |
def clean_generated_text(text):
|
@@ -93,74 +94,86 @@ def main():
|
|
93 |
It's the best free waifu generator out there, providing everything you need to bring your waifu to life.
|
94 |
""")
|
95 |
|
96 |
-
#
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
name = st.text_input("Name of the Waifu")
|
100 |
hair_color = st.selectbox("Hair Color", ["Blonde", "Brunette", "Red", "Black", "Blue", "Pink"])
|
101 |
-
eye_color = st.selectbox("Eye Color", ["Blue", "Green", "Brown", "Hazel", "Red", "Purple"])
|
102 |
-
height = st.text_input("Height (e.g., 5'6\")")
|
103 |
-
age = st.text_input("Age")
|
104 |
personality = st.selectbox("Personality", ["Tsundere", "Yandere", "Kuudere", "Dandere", "Genki", "Normal"])
|
105 |
outfit_style = st.selectbox("Outfit Style", ["School Uniform", "Maid Outfit", "Casual", "Kimono", "Gothic Lolita"])
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
st.session_state
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
if __name__ == "__main__":
|
166 |
main()
|
|
|
11 |
text_client = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.1")
|
12 |
image_client = Client("Boboiazumi/animagine-xl-3.1")
|
13 |
|
14 |
+
def format_prompt_for_description(name, hair_color, personality, outfit_style, hobbies, favorite_food, background_story, **kwargs):
|
15 |
+
prompt = f"Create a waifu character named {name} with {hair_color} hair, a {personality} personality, and wearing a {outfit_style}. "
|
16 |
+
prompt += f"Her hobbies include {hobbies}. Her favorite food is {favorite_food}. Here is her background story: {background_story}."
|
17 |
+
for key, value in kwargs.items():
|
18 |
+
prompt += f" Her {key} is {value}."
|
19 |
return prompt
|
20 |
|
21 |
+
def format_prompt_for_image(name, hair_color, personality, outfit_style, **kwargs):
|
22 |
+
prompt = f"Generate an image prompt for a waifu character named {name} with {hair_color} hair, a {personality} personality, and wearing a {outfit_style}."
|
23 |
+
for key, value in kwargs.items():
|
24 |
+
prompt += f" She is in a {key} setting, posing in a {value}."
|
25 |
return prompt
|
26 |
|
27 |
def clean_generated_text(text):
|
|
|
94 |
It's the best free waifu generator out there, providing everything you need to bring your waifu to life.
|
95 |
""")
|
96 |
|
97 |
+
# Layout containers
|
98 |
+
left_col, right_col = st.columns(2)
|
99 |
+
|
100 |
+
with left_col:
|
101 |
+
st.header("Waifu Settings")
|
102 |
+
|
103 |
+
# Basic settings
|
104 |
name = st.text_input("Name of the Waifu")
|
105 |
hair_color = st.selectbox("Hair Color", ["Blonde", "Brunette", "Red", "Black", "Blue", "Pink"])
|
|
|
|
|
|
|
106 |
personality = st.selectbox("Personality", ["Tsundere", "Yandere", "Kuudere", "Dandere", "Genki", "Normal"])
|
107 |
outfit_style = st.selectbox("Outfit Style", ["School Uniform", "Maid Outfit", "Casual", "Kimono", "Gothic Lolita"])
|
108 |
+
|
109 |
+
# Advanced settings
|
110 |
+
with st.expander("More Options"):
|
111 |
+
hobbies = st.text_input("Hobbies")
|
112 |
+
favorite_food = st.text_input("Favorite Food")
|
113 |
+
background_story = st.text_area("Background Story")
|
114 |
+
eye_color = st.selectbox("Eye Color", ["Blue", "Green", "Brown", "Hazel", "Red", "Purple"], index=0)
|
115 |
+
height = st.text_input("Height (e.g., 5'6\")", "")
|
116 |
+
age = st.text_input("Age", "")
|
117 |
+
favorite_quote = st.text_input("Favorite Quote", "")
|
118 |
+
strengths = st.text_input("Strengths", "")
|
119 |
+
weaknesses = st.text_input("Weaknesses", "")
|
120 |
+
goals = st.text_input("Goals", "")
|
121 |
+
background_setting = st.selectbox("Background Setting", ["School", "City", "Fantasy World", "Beach", "Park"], index=0)
|
122 |
+
pose = st.selectbox("Pose", ["Standing", "Sitting", "Action Pose", "Lying Down"], index=0)
|
123 |
+
system_prompt = st.text_input("Optional System Prompt", "")
|
124 |
+
|
125 |
+
# Advanced settings sliders
|
126 |
+
with st.expander("Advanced Settings"):
|
127 |
+
temperature = st.slider("Temperature", 0.0, 1.0, 0.9, step=0.05)
|
128 |
+
max_new_tokens = st.slider("Max new tokens", 0, 8192, 512, step=64)
|
129 |
+
top_p = st.slider("Top-p (nucleus sampling)", 0.0, 1.0, 0.95, step=0.05)
|
130 |
+
repetition_penalty = st.slider("Repetition penalty", 1.0, 2.0, 1.0, step=0.05)
|
131 |
+
|
132 |
+
# Initialize session state for generated text and image prompt
|
133 |
+
if "character_description" not in st.session_state:
|
134 |
+
st.session_state.character_description = ""
|
135 |
+
if "image_prompt" not in st.session_state:
|
136 |
+
st.session_state.image_prompt = ""
|
137 |
+
if "image_paths" not in st.session_state:
|
138 |
+
st.session_state.image_paths = []
|
139 |
+
|
140 |
+
# Generate button
|
141 |
+
if st.button("Generate Waifu"):
|
142 |
+
with st.spinner("Generating waifu character..."):
|
143 |
+
description_prompt = format_prompt_for_description(
|
144 |
+
name, hair_color, personality, outfit_style, hobbies, favorite_food, background_story,
|
145 |
+
eye_color=eye_color, height=height, age=age, favorite_quote=favorite_quote, strengths=strengths,
|
146 |
+
weaknesses=weaknesses, goals=goals
|
147 |
+
)
|
148 |
+
image_prompt = format_prompt_for_image(
|
149 |
+
name, hair_color, personality, outfit_style,
|
150 |
+
background_setting=background_setting, pose=pose
|
151 |
+
)
|
152 |
+
|
153 |
+
# Generate character description
|
154 |
+
st.session_state.character_description = generate_text(description_prompt, temperature, max_new_tokens, top_p, repetition_penalty)
|
155 |
+
|
156 |
+
# Generate image prompt
|
157 |
+
st.session_state.image_prompt = generate_text(image_prompt, temperature, max_new_tokens, top_p, repetition_penalty)
|
158 |
+
|
159 |
+
# Generate image from image prompt
|
160 |
+
st.session_state.image_paths = generate_image(st.session_state.image_prompt)
|
161 |
+
|
162 |
+
st.success("Waifu character generated!")
|
163 |
+
|
164 |
+
with right_col:
|
165 |
+
st.header("Generated Waifu")
|
166 |
+
# Display the generated character and image prompt
|
167 |
+
if st.session_state.character_description:
|
168 |
+
st.subheader("Generated Waifu Character")
|
169 |
+
st.write(st.session_state.character_description)
|
170 |
+
if st.session_state.image_prompt:
|
171 |
+
st.subheader("Image Prompt")
|
172 |
+
st.write(st.session_state.image_prompt)
|
173 |
+
if st.session_state.image_paths:
|
174 |
+
st.subheader("Generated Image")
|
175 |
+
for image_path in st.session_state.image_paths:
|
176 |
+
st.image(image_path, caption="Generated Waifu Image")
|
177 |
|
178 |
if __name__ == "__main__":
|
179 |
main()
|