Update app.py
Browse files
app.py
CHANGED
|
@@ -11,17 +11,13 @@ 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, personality, outfit_style, hobbies, favorite_food, background_story
|
| 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
|
| 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):
|
|
@@ -87,93 +83,64 @@ def generate_image(prompt):
|
|
| 87 |
return None
|
| 88 |
|
| 89 |
def main():
|
| 90 |
-
st.title("
|
| 91 |
-
st.write("""
|
| 92 |
-
Welcome to the Free Waifu Character Generator! This app allows you to create a unique waifu with just one click.
|
| 93 |
-
Generate a detailed bio/background story, a prompt for an image, and the image itself.
|
| 94 |
-
It's the best free waifu generator out there, providing everything you need to bring your waifu to life.
|
| 95 |
-
""")
|
| 96 |
|
| 97 |
-
#
|
| 98 |
-
|
| 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 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
st.session_state.
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 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()
|
|
|
|
| 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):
|
| 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 |
return prompt
|
| 18 |
|
| 19 |
+
def format_prompt_for_image(name, hair_color, personality, outfit_style):
|
| 20 |
prompt = f"Generate an image prompt for a waifu character named {name} with {hair_color} hair, a {personality} personality, and wearing a {outfit_style}."
|
|
|
|
|
|
|
| 21 |
return prompt
|
| 22 |
|
| 23 |
def clean_generated_text(text):
|
|
|
|
| 83 |
return None
|
| 84 |
|
| 85 |
def main():
|
| 86 |
+
st.title("Enhanced Waifu Character Generator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
# User inputs
|
| 89 |
+
col1, col2 = st.columns(2)
|
| 90 |
+
with col1:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
name = st.text_input("Name of the Waifu")
|
| 92 |
hair_color = st.selectbox("Hair Color", ["Blonde", "Brunette", "Red", "Black", "Blue", "Pink"])
|
| 93 |
personality = st.selectbox("Personality", ["Tsundere", "Yandere", "Kuudere", "Dandere", "Genki", "Normal"])
|
| 94 |
outfit_style = st.selectbox("Outfit Style", ["School Uniform", "Maid Outfit", "Casual", "Kimono", "Gothic Lolita"])
|
| 95 |
+
with col2:
|
| 96 |
+
hobbies = st.text_input("Hobbies")
|
| 97 |
+
favorite_food = st.text_input("Favorite Food")
|
| 98 |
+
background_story = st.text_area("Background Story")
|
| 99 |
+
system_prompt = st.text_input("Optional System Prompt", "")
|
| 100 |
+
|
| 101 |
+
# Advanced settings
|
| 102 |
+
with st.expander("Advanced Settings"):
|
| 103 |
+
temperature = st.slider("Temperature", 0.0, 1.0, 0.9, step=0.05)
|
| 104 |
+
max_new_tokens = st.slider("Max new tokens", 0, 8192, 512, step=64)
|
| 105 |
+
top_p = st.slider("Top-p (nucleus sampling)", 0.0, 1.0, 0.95, step=0.05)
|
| 106 |
+
repetition_penalty = st.slider("Repetition penalty", 1.0, 2.0, 1.0, step=0.05)
|
| 107 |
+
|
| 108 |
+
# Initialize session state for generated text and image prompt
|
| 109 |
+
if "character_description" not in st.session_state:
|
| 110 |
+
st.session_state.character_description = ""
|
| 111 |
+
if "image_prompt" not in st.session_state:
|
| 112 |
+
st.session_state.image_prompt = ""
|
| 113 |
+
if "image_paths" not in st.session_state:
|
| 114 |
+
st.session_state.image_paths = []
|
| 115 |
+
|
| 116 |
+
# Generate button
|
| 117 |
+
if st.button("Generate Waifu"):
|
| 118 |
+
with st.spinner("Generating waifu character..."):
|
| 119 |
+
description_prompt = format_prompt_for_description(name, hair_color, personality, outfit_style, hobbies, favorite_food, background_story)
|
| 120 |
+
image_prompt = format_prompt_for_image(name, hair_color, personality, outfit_style)
|
| 121 |
+
|
| 122 |
+
# Generate character description
|
| 123 |
+
st.session_state.character_description = generate_text(description_prompt, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 124 |
+
|
| 125 |
+
# Generate image prompt
|
| 126 |
+
st.session_state.image_prompt = generate_text(image_prompt, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 127 |
+
|
| 128 |
+
# Generate image from image prompt
|
| 129 |
+
st.session_state.image_paths = generate_image(st.session_state.image_prompt)
|
| 130 |
+
|
| 131 |
+
st.success("Waifu character generated!")
|
| 132 |
+
|
| 133 |
+
# Display the generated character and image prompt
|
| 134 |
+
if st.session_state.character_description:
|
| 135 |
+
st.subheader("Generated Waifu Character")
|
| 136 |
+
st.write(st.session_state.character_description)
|
| 137 |
+
if st.session_state.image_prompt:
|
| 138 |
+
st.subheader("Image Prompt")
|
| 139 |
+
st.write(st.session_state.image_prompt)
|
| 140 |
+
if st.session_state.image_paths:
|
| 141 |
+
st.subheader("Generated Image")
|
| 142 |
+
for image_path in st.session_state.image_paths:
|
| 143 |
+
st.image(image_path, caption="Generated Waifu Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|
| 146 |
main()
|