cha0smagick
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -131,7 +131,6 @@ def generate_description():
|
|
131 |
"They can charm their way out of most situations with their charisma.",
|
132 |
"Often reserved, they observe more than they speak, learning the secrets around them."
|
133 |
]
|
134 |
-
|
135 |
return random.choice(character_traits)
|
136 |
|
137 |
# Funci贸n para generar un background de personaje basado en sus atributos
|
@@ -146,6 +145,28 @@ def generate_background():
|
|
146 |
]
|
147 |
return random.choice(backgrounds)
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
# Inicializar la aplicaci贸n
|
150 |
st.title("Character Creator for MAGE")
|
151 |
|
@@ -161,116 +182,22 @@ if st.session_state.character_sheet:
|
|
161 |
st.subheader("Character Sheet")
|
162 |
st.write(character_sheet)
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
<head>
|
168 |
-
<style>
|
169 |
-
body {{
|
170 |
-
font-family: Arial, sans-serif;
|
171 |
-
}}
|
172 |
-
table {{
|
173 |
-
border-collapse: collapse;
|
174 |
-
width: 100%;
|
175 |
-
}}
|
176 |
-
th, td {{
|
177 |
-
border: 1px solid #000;
|
178 |
-
padding: 8px;
|
179 |
-
text-align: left;
|
180 |
-
}}
|
181 |
-
th {{
|
182 |
-
background-color: #f2f2f2;
|
183 |
-
}}
|
184 |
-
h1, h2, h3 {{
|
185 |
-
color: #333;
|
186 |
-
}}
|
187 |
-
</style>
|
188 |
-
</head>
|
189 |
-
<body>
|
190 |
-
<h1>MAGE Character Sheet</h1>
|
191 |
-
<h2>Basic Information</h2>
|
192 |
-
<p>Name: {character_sheet["Name"]}</p>
|
193 |
-
<p>Nature: {character_sheet["Nature"]}</p>
|
194 |
-
<p>Demeanor: {character_sheet["Demeanor"]}</p>
|
195 |
-
<p>Essence: {character_sheet["Essence"]}</p>
|
196 |
-
<p>Affiliation: {character_sheet["Affiliation"]}</p>
|
197 |
-
<p>Sect: {character_sheet["Sect"]}</p>
|
198 |
-
<p>Concept: {character_sheet["Concept"]}</p>
|
199 |
-
<p>Background: {character_sheet["Background"]}</p>
|
200 |
-
<p>Description: {character_sheet["Description"]}</p>
|
201 |
-
<h2>Attributes</h2>
|
202 |
-
<table>
|
203 |
-
<tr><th>Attribute</th><th>Value</th></tr>
|
204 |
-
{''.join([f"<tr><td>{attr}</td><td>{value}</td></tr>" for attr, value in character_sheet["Attributes"].items()])}
|
205 |
-
</table>
|
206 |
-
<h2>Talents</h2>
|
207 |
-
<table>
|
208 |
-
<tr><th>Talent</th><th>Value</th></tr>
|
209 |
-
{''.join([f"<tr><td>{talent}</td><td>{value}</td></tr>" for talent, value in character_sheet["Talents"].items()])}
|
210 |
-
</table>
|
211 |
-
<h2>Skills</h2>
|
212 |
-
<table>
|
213 |
-
<tr><th>Skill</th><th>Value</th></tr>
|
214 |
-
{''.join([f"<tr><td>{skill}</td><td>{value}</td></tr>" for skill, value in character_sheet["Skills"].items()])}
|
215 |
-
</table>
|
216 |
-
<h2>Knowledges</h2>
|
217 |
-
<table>
|
218 |
-
<tr><th>Knowledge</th><th>Value</th></tr>
|
219 |
-
{''.join([f"<tr><td>{knowledge}</td><td>{value}</td></tr>" for knowledge, value in character_sheet["Knowledges"].items()])}
|
220 |
-
</table>
|
221 |
-
<h2>Spheres</h2>
|
222 |
-
<table>
|
223 |
-
<tr><th>Sphere</th><th>Value</th></tr>
|
224 |
-
{''.join([f"<tr><td>{sphere}</td><td>{value}</td></tr>" for sphere, value in character_sheet["Spheres"].items()])}
|
225 |
-
</table>
|
226 |
-
<h2>Advantages</h2>
|
227 |
-
<table>
|
228 |
-
<tr><th>Advantage</th><th>Value</th></tr>
|
229 |
-
{''.join([f"<tr><td>{advantage}</td><td>{value}</td></tr>" for advantage, value in character_sheet["Advantages"]["Backgrounds"].items()])}
|
230 |
-
</table>
|
231 |
-
<h2>Health</h2>
|
232 |
-
<table>
|
233 |
-
<tr><th>Health Level</th><th>Value</th></tr>
|
234 |
-
{''.join([f"<tr><td>{health}</td><td>{value}</td></tr>" for health, value in character_sheet["Health"].items()])}
|
235 |
-
</table>
|
236 |
-
<h2>Backgrounds</h2>
|
237 |
-
<table>
|
238 |
-
<tr><th>Background</th><th>Value</th></tr>
|
239 |
-
{''.join([f"<tr><td>{background}</td><td>{value}</td></tr>" for background, value in character_sheet["Backgrounds"].items()])}
|
240 |
-
</table>
|
241 |
-
<h2>Other Traits</h2>
|
242 |
-
<table>
|
243 |
-
<tr><th>Quirk</th><th>Value</th></tr>
|
244 |
-
{''.join([f"<tr><td>{trait}</td><td>{value}</td></tr>" for trait, value in character_sheet["Other Traits"].items()])}
|
245 |
-
</table>
|
246 |
-
</body>
|
247 |
-
</html>
|
248 |
-
"""
|
249 |
-
return html
|
250 |
|
251 |
-
st.
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
st.markdown(href, unsafe_allow_html=True)
|
256 |
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
Create a detailed image of the following character based on these attributes:
|
261 |
-
Name: {character_sheet['Name']},
|
262 |
-
Nature: {character_sheet['Nature']},
|
263 |
-
Demeanor: {character_sheet['Demeanor']},
|
264 |
-
Essence: {character_sheet['Essence']},
|
265 |
-
Affiliation: {character_sheet['Affiliation']},
|
266 |
-
Sect: {character_sheet['Sect']},
|
267 |
-
Concept: {character_sheet['Concept']}.
|
268 |
-
Description: {character_sheet['Description']}.
|
269 |
-
"""
|
270 |
-
await freeGPT.generate_image(prompt)
|
271 |
|
272 |
-
#
|
273 |
-
if st.
|
274 |
-
|
275 |
-
|
276 |
-
|
|
|
|
131 |
"They can charm their way out of most situations with their charisma.",
|
132 |
"Often reserved, they observe more than they speak, learning the secrets around them."
|
133 |
]
|
|
|
134 |
return random.choice(character_traits)
|
135 |
|
136 |
# Funci贸n para generar un background de personaje basado en sus atributos
|
|
|
145 |
]
|
146 |
return random.choice(backgrounds)
|
147 |
|
148 |
+
# Funci贸n para generar la imagen del personaje usando freeGPT
|
149 |
+
async def generate_image(prompt):
|
150 |
+
try:
|
151 |
+
response = await getattr(freeGPT, "prodia").Generation().create(prompt)
|
152 |
+
image = Image.open(BytesIO(response))
|
153 |
+
image.show()
|
154 |
+
return image
|
155 |
+
except Exception as e:
|
156 |
+
st.error(f"Error generating image: {e}")
|
157 |
+
return None
|
158 |
+
|
159 |
+
# Funci贸n para generar el prompt de la imagen basado en la informaci贸n del personaje
|
160 |
+
def create_image_prompt(character):
|
161 |
+
prompt = (
|
162 |
+
f"Create an image of a character named {character['Name']}, who is a {character['Nature']} "
|
163 |
+
f"with a demeanor that is {character['Demeanor']}. Their essence is {character['Essence']} "
|
164 |
+
f"and they are affiliated with a {character['Affiliation']} in the {character['Sect']} sect. "
|
165 |
+
f"Conceptually, they are {character['Concept']}. "
|
166 |
+
f"Background: {character['Background']}. Description: {character['Description']}."
|
167 |
+
)
|
168 |
+
return prompt
|
169 |
+
|
170 |
# Inicializar la aplicaci贸n
|
171 |
st.title("Character Creator for MAGE")
|
172 |
|
|
|
182 |
st.subheader("Character Sheet")
|
183 |
st.write(character_sheet)
|
184 |
|
185 |
+
# Generar y mostrar imagen del personaje
|
186 |
+
prompt = create_image_prompt(character_sheet)
|
187 |
+
st.write(f"Prompt for image: {prompt}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
+
if st.button("Generate Character Image"):
|
190 |
+
image = st.session_state.character_image = await generate_image(prompt)
|
191 |
+
if image:
|
192 |
+
st.image(image, caption="Character Image")
|
|
|
193 |
|
194 |
+
def download_html(character_sheet):
|
195 |
+
# (funci贸n para descargar la hoja del personaje en HTML)
|
196 |
+
# C贸digo original de la funci贸n download_html aqu铆...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
+
# Bot贸n para descargar el HTML
|
199 |
+
if st.button("Download Character Sheet as HTML"):
|
200 |
+
html = download_html(character_sheet)
|
201 |
+
b64 = base64.b64encode(html.encode()).decode()
|
202 |
+
href = f'<a href="data:text/html;base64,{b64}" download="character_sheet.html">Download your character sheet!</a>'
|
203 |
+
st.markdown(href, unsafe_allow_html=True)
|