Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,16 @@ clientOpenAI = OpenAI(
|
|
| 21 |
)
|
| 22 |
|
| 23 |
ambientazioni = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
"Sacro Romano Impero": {
|
| 25 |
"nome": "Sacro Romano Impero",
|
| 26 |
"stile_immagine": (
|
|
@@ -252,12 +262,21 @@ def generate_image(prompt, max_retries=5):
|
|
| 252 |
st.error("Numero massimo di tentativi raggiunto. Impossibile generare le immagini.")
|
| 253 |
return None
|
| 254 |
|
| 255 |
-
def generate_images(character: Character, carta_azione: ActionCard, stile_immagine, num_immagini):
|
| 256 |
# Lista per salvare le immagini generate come tuple (nome_file, bytes)
|
| 257 |
if character:
|
| 258 |
-
prompt = f"{character.english_description} {stile_immagine}. (INSERT TEXT NAME = {character.nome})"
|
| 259 |
images_bytes_list = []
|
| 260 |
-
if character.nome
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
st.subheader(f"{character.nome} 🦸♂️")
|
| 262 |
st.write(
|
| 263 |
f"- **Classe:** {character.classe}\n"
|
|
@@ -299,20 +318,28 @@ def main():
|
|
| 299 |
nome_ambientazione = ambientazioni[selected_ambientazione]["nome"]
|
| 300 |
stile_immagine = st.sidebar.text_area("Stile Immagine", stile_default, disabled=False)
|
| 301 |
auto = False
|
| 302 |
-
prompt_input = st.sidebar.text_input("Prompt Immagine (in inglese)", value="Soldier", disabled=auto)
|
| 303 |
-
num_immagini = st.sidebar.slider("Variazioni Immagini", min_value=1, max_value=6, value=2)
|
| 304 |
auto = st.sidebar.toggle(label= 'Generazione automatica', value = True)
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
creativita = st.sidebar.slider("Creativita", min_value=0.1, max_value=1.0, value=0.8, step=0.1)
|
| 309 |
submit_button = st.sidebar.button(label="Genera Immagine", type="primary", use_container_width=True)
|
| 310 |
st.write("Forgia il tuo **destino nell'Impero**: crea, combatti e domina nel più grande gioco di ruolo a carte generato dall'AI")
|
| 311 |
|
| 312 |
if submit_button:
|
| 313 |
-
if not prompt_input.strip() and not auto:
|
| 314 |
-
st.error("Per favore, inserisci un prompt per l'immagine!")
|
| 315 |
-
return
|
| 316 |
carte_azione = None
|
| 317 |
characters = None
|
| 318 |
if auto:
|
|
@@ -340,7 +367,7 @@ def main():
|
|
| 340 |
images = []
|
| 341 |
if characters:
|
| 342 |
for character in characters.personaggi:
|
| 343 |
-
images.extend(generate_images(character, None, stile_immagine, num_immagini))
|
| 344 |
if carte_azione:
|
| 345 |
for carta_azione in carte_azione.carte_azione:
|
| 346 |
images.extend(generate_images(None, carta_azione, stile_immagine, num_immagini))
|
|
@@ -361,4 +388,4 @@ def main():
|
|
| 361 |
|
| 362 |
if __name__ == "__main__":
|
| 363 |
st.set_page_config(page_title="Imperium AI", page_icon="🏰", layout="wide")
|
| 364 |
-
main()
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
ambientazioni = {
|
| 24 |
+
"Roma Repubblicana": {
|
| 25 |
+
"nome": "Roma Repubblicana",
|
| 26 |
+
"stile_immagine": (
|
| 27 |
+
"A painterly, highly detailed visual narrative rich with graphic elements Roman Repubblic "
|
| 28 |
+
"Incorporate ornate Roman columns, laurel wreaths, engraved inscriptions, and intricate mosaic patterns. "
|
| 29 |
+
"Textures of weathered marble, aged frescoes, and tattered papyrus blend with a dramatic chiaroscuro effect. "
|
| 30 |
+
"A color palette of imperial red, bronze, and muted gold accentuates secretive senatorial silhouettes and subtle sigils. "
|
| 31 |
+
"Designed for a tabletop card game, this style captures clandestine intrigue and political tension with dynamic visual flair."
|
| 32 |
+
)
|
| 33 |
+
},
|
| 34 |
"Sacro Romano Impero": {
|
| 35 |
"nome": "Sacro Romano Impero",
|
| 36 |
"stile_immagine": (
|
|
|
|
| 262 |
st.error("Numero massimo di tentativi raggiunto. Impossibile generare le immagini.")
|
| 263 |
return None
|
| 264 |
|
| 265 |
+
def generate_images(character: Character, carta_azione: ActionCard, stile_immagine, num_immagini, tipo_carta: str = None, nome_carta: str = None, colore_bordo: str = None):
|
| 266 |
# Lista per salvare le immagini generate come tuple (nome_file, bytes)
|
| 267 |
if character:
|
|
|
|
| 268 |
images_bytes_list = []
|
| 269 |
+
if character.nome == "":
|
| 270 |
+
if tipo_carta == "Personaggio":
|
| 271 |
+
prompt = f"{character.english_description} WITH THIS BOLD INSCRIPTION '{nome_carta}'. BORDER COLOR = {colore_bordo}). Use this Style: {stile_immagine}"
|
| 272 |
+
if tipo_carta == "Fronte":
|
| 273 |
+
prompt = f"FRONT OF CARD GAME (WITH THIS BOLD INSCRIPTION IN THE CENTER OF THE CARD = '{nome_carta}'. BORDER COLOR = {colore_bordo}). Use this Syle: {stile_immagine}"
|
| 274 |
+
if tipo_carta == "Retro":
|
| 275 |
+
prompt = ("Design an ornate playing card back with symmetrical filigree"
|
| 276 |
+
"At the center, prominently display the name '" + nome_carta + "' in an elegant, calligraphic style. ")
|
| 277 |
+
prompt += f"BACKGROUND COLOR = {colore_bordo}. Use this Syle: {stile_immagine}"
|
| 278 |
+
else:
|
| 279 |
+
prompt = f"{character.english_description} {stile_immagine}. (INSERT TEXT NAME = {character.nome})"
|
| 280 |
st.subheader(f"{character.nome} 🦸♂️")
|
| 281 |
st.write(
|
| 282 |
f"- **Classe:** {character.classe}\n"
|
|
|
|
| 318 |
nome_ambientazione = ambientazioni[selected_ambientazione]["nome"]
|
| 319 |
stile_immagine = st.sidebar.text_area("Stile Immagine", stile_default, disabled=False)
|
| 320 |
auto = False
|
|
|
|
|
|
|
| 321 |
auto = st.sidebar.toggle(label= 'Generazione automatica', value = True)
|
| 322 |
+
prompt_input = ""
|
| 323 |
+
if auto == False:
|
| 324 |
+
tipo_carta = st.sidebar.selectbox("Tipo Carta",("Personaggio", "Fronte", "Retro"))
|
| 325 |
+
if tipo_carta == "Personaggio":
|
| 326 |
+
prompt_input = st.sidebar.text_input("Prompt Immagine (in inglese)", value="Soldier")
|
| 327 |
+
nome_carta = st.sidebar.text_input("Nome Carta", value="Carmine")
|
| 328 |
+
colore_bordo = st.sidebar.selectbox("Colore Bordo",("Blue", "Red", "Yellow", "Green", "Pink", "Black", "White"))
|
| 329 |
+
else:
|
| 330 |
+
num_personaggi = st.sidebar.slider("Personaggi", min_value=0, max_value=30, value=5, disabled=not auto)
|
| 331 |
+
num_carte_azione = st.sidebar.slider("Carte Azione", min_value=0, max_value=10, value=0, disabled=not auto)
|
| 332 |
+
genera_regolamento = st.sidebar.toggle(label= 'Regolamento', value = True, disabled=not auto)
|
| 333 |
+
tipo_carta = None
|
| 334 |
+
nome_carta = None
|
| 335 |
+
colore_bordo = None
|
| 336 |
+
|
| 337 |
+
num_immagini = st.sidebar.slider("Variazioni Immagini", min_value=1, max_value=6, value=2)
|
| 338 |
creativita = st.sidebar.slider("Creativita", min_value=0.1, max_value=1.0, value=0.8, step=0.1)
|
| 339 |
submit_button = st.sidebar.button(label="Genera Immagine", type="primary", use_container_width=True)
|
| 340 |
st.write("Forgia il tuo **destino nell'Impero**: crea, combatti e domina nel più grande gioco di ruolo a carte generato dall'AI")
|
| 341 |
|
| 342 |
if submit_button:
|
|
|
|
|
|
|
|
|
|
| 343 |
carte_azione = None
|
| 344 |
characters = None
|
| 345 |
if auto:
|
|
|
|
| 367 |
images = []
|
| 368 |
if characters:
|
| 369 |
for character in characters.personaggi:
|
| 370 |
+
images.extend(generate_images(character, None, stile_immagine, num_immagini, tipo_carta, nome_carta, colore_bordo))
|
| 371 |
if carte_azione:
|
| 372 |
for carta_azione in carte_azione.carte_azione:
|
| 373 |
images.extend(generate_images(None, carta_azione, stile_immagine, num_immagini))
|
|
|
|
| 388 |
|
| 389 |
if __name__ == "__main__":
|
| 390 |
st.set_page_config(page_title="Imperium AI", page_icon="🏰", layout="wide")
|
| 391 |
+
main()
|