randeom commited on
Commit
efdf463
·
verified ·
1 Parent(s): d8dd717

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -72
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, eye_color, height, age, personality, outfit_style, hobbies, favorite_food, favorite_quote, strengths, weaknesses, goals, background_story):
15
- prompt = f"Create a waifu character named {name} with {hair_color} hair, {eye_color} eyes, a {personality} personality, and wearing a {outfit_style}. "
16
- prompt += f"She is {height} tall and {age} years old. Her hobbies include {hobbies}. Her favorite food is {favorite_food}. "
17
- prompt += f"Her favorite quote is: '{favorite_quote}'. She has the following strengths: {strengths}. Her weaknesses include {weaknesses}. "
18
- prompt += f"Her goals are: {goals}. Here is her background story: {background_story}."
19
  return prompt
20
 
21
- def format_prompt_for_image(name, hair_color, eye_color, personality, outfit_style, background_setting, pose):
22
- prompt = f"Generate an image prompt for a waifu character named {name} with {hair_color} hair, {eye_color} eyes, a {personality} personality, and wearing a {outfit_style}. "
23
- prompt += f"She is in a {background_setting} setting, posing in a {pose}."
 
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
- # User inputs
97
- col1, col2 = st.columns(2)
98
- with col1:
 
 
 
 
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
- with col2:
107
- hobbies = st.text_input("Hobbies")
108
- favorite_food = st.text_input("Favorite Food")
109
- favorite_quote = st.text_input("Favorite Quote")
110
- strengths = st.text_input("Strengths")
111
- weaknesses = st.text_input("Weaknesses")
112
- goals = st.text_input("Goals")
113
- background_story = st.text_area("Background Story")
114
- background_setting = st.selectbox("Background Setting", ["School", "City", "Fantasy World", "Beach", "Park"])
115
- pose = st.selectbox("Pose", ["Standing", "Sitting", "Action Pose", "Lying Down"])
116
- system_prompt = st.text_input("Optional System Prompt", "")
117
-
118
- # Advanced settings
119
- with st.expander("Advanced Settings"):
120
- temperature = st.slider("Temperature", 0.0, 1.0, 0.9, step=0.05)
121
- max_new_tokens = st.slider("Max new tokens", 0, 8192, 512, step=64)
122
- top_p = st.slider("Top-p (nucleus sampling)", 0.0, 1.0, 0.95, step=0.05)
123
- repetition_penalty = st.slider("Repetition penalty", 1.0, 2.0, 1.0, step=0.05)
124
-
125
- # Initialize session state for generated text and image prompt
126
- if "character_description" not in st.session_state:
127
- st.session_state.character_description = ""
128
- if "image_prompt" not in st.session_state:
129
- st.session_state.image_prompt = ""
130
- if "image_paths" not in st.session_state:
131
- st.session_state.image_paths = []
132
-
133
- # Generate button
134
- if st.button("Generate Waifu"):
135
- with st.spinner("Generating waifu character..."):
136
- description_prompt = format_prompt_for_description(
137
- name, hair_color, eye_color, height, age, personality, outfit_style,
138
- hobbies, favorite_food, favorite_quote, strengths, weaknesses, goals, background_story
139
- )
140
- image_prompt = format_prompt_for_image(name, hair_color, eye_color, personality, outfit_style, background_setting, pose)
141
-
142
- # Generate character description
143
- st.session_state.character_description = generate_text(description_prompt, temperature, max_new_tokens, top_p, repetition_penalty)
144
-
145
- # Generate image prompt
146
- st.session_state.image_prompt = generate_text(image_prompt, temperature, max_new_tokens, top_p, repetition_penalty)
147
-
148
- # Generate image from image prompt
149
- st.session_state.image_paths = generate_image(st.session_state.image_prompt)
150
-
151
- st.success("Waifu character generated!")
152
-
153
- # Display the generated character and image prompt
154
- if st.session_state.character_description:
155
- st.subheader("Generated Waifu Character")
156
- st.write(st.session_state.character_description)
157
- if st.session_state.image_prompt:
158
- st.subheader("Image Prompt")
159
- st.write(st.session_state.image_prompt)
160
- if st.session_state.image_paths:
161
- st.subheader("Generated Image")
162
- for image_path in st.session_state.image_paths:
163
- st.image(image_path, caption="Generated Waifu Image")
 
 
 
 
 
 
 
 
 
 
 
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()