randeom commited on
Commit
7249a81
·
verified ·
1 Parent(s): 6bc0124

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -88
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, **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):
@@ -87,93 +83,64 @@ def generate_image(prompt):
87
  return None
88
 
89
  def main():
90
- st.title("Free Waifu Character Generator")
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
- # 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()
 
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()