Spaces:
Sleeping
Sleeping
Update app.py
Browse files20 unmodified lines2122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311329 unmodified lines14214314410714514614714814915015115215313 unmodified lines1671681691311701711721737 unmodified lines18118218318418518618725 unmodified lines21321421517621621721821925 unmodified lines2452462472082482492502512522122532542552 unmodified lines25825926022126126226326426522626626726826920 unmodified lines)
ambientazioni = { "Sacro Romano Impero": { "nome": "Sacro Romano Impero", "stile_immagine": ( "Highly detailed, painterly style with a historical yet stylized aesthetic. " "Rich textures, ornate patterns, and a color palette dominated by imperial gold, " "deep red, and aged marble tones. Inspired by medieval European art, " "gothic illuminations, and the grandeur of cathedrals. " "Designed for a tabletop card game, ensuring clarity, readability, " "and a visually immersive experience." ) }, "Antico Egitto": { "nome": "Antico Egitto", "stile_immagine": ( "A stylized Egyptian art style, reminiscent of ancient tomb paintings. " "Use sandy, ochre and turquoise color palette, with hieroglyphic details. " "Geometric shapes and patterns evoke the grandeur of pharaohs and pyramids. " "Designed for a tabletop card game with clarity and distinct thematic flourishes." ) }, "Dinastia Han Cinese": { "nome": "Dinastia Han Cinese", "stile_immagine": ( "Traditional Chinese art style, with ink wash influences, ornate calligraphy, " "and vibrant silk robe patterns. Use subtle brush strokes and bold reds/golds. " "Designed for clarity in a card game with a distinctly ancient Asian aesthetic." ) }, "Impero Persiano": { "nome": "Impero Persiano", "stile_immagine": ( "Intricate Persian miniature style, lavish details, floral ornaments, " "and strong jewel tones like turquoise, gold, and purple. Stylized silhouettes " "in a rich, decorative composition suited for card art." ) }, "Impero Ottomano": { "nome": "Impero Ottomano", "stile_immagine": ( "Ottoman illuminated manuscript style, featuring ornate arabesque borders, " "rich gold leaf, and deep sapphire or emerald backgrounds. " "Figures with flowing robes and turbans, capturing courtly splendor." ) }, "Maya": { "nome": "Maya", "stile_immagine": ( "Mesoamerican style with stylized glyphs, stepped pyramids, and bright colors. " "Incorporate traditional motifs of jaguars and feathers in a decorative, yet readable card layout." ) }, "Vichinghi": { "nome": "Vichinghi", "stile_immagine": ( "Norse-inspired style, with knotwork borders, runic inscriptions, and rugged, " "weathered textures. Use earthy colors and references to Viking longships, " "mythology, and wooden carvings. Balanced for a legible card game design." ) }, "Grecia Antica": { "nome": "Grecia Antica", "stile_immagine": ( "Classic Greek art style with white marble textures, red-figure pottery motifs, " "and references to mythological scenes. Elegant lines and columns, evoking the " "aesthetics of ancient vases and statues. Ideal for a tabletop card game with readable design." ) }, } "Sacro Romano Impero": { "nome": "Sacro Romano Impero", "stile_immagine": ( "Highly detailed, painterly style with a historical yet stylized aesthetic. " "Rich textures, ornate patterns, and a color palette dominated by imperial gold, " "deep red, and aged marble tones. Inspired by medieval European art, " "gothic illuminations, and the grandeur of cathedrals. " "Designed for a tabletop card game, ensuring clarity, readability, " "and a visually immersive experience." ) }, "Antico Egitto": { "nome": "Antico Egitto", "stile_immagine": ( "A stylized Egyptian art style, reminiscent of ancient tomb paintings. " "Use sandy, ochre and turquoise color palette, with hieroglyphic details. " "Geometric shapes and patterns evoke the grandeur of pharaohs and pyramids. " "Designed for a tabletop card game with clarity and distinct thematic flourishes." ) }, "Dinastia Han Cinese": { "nome": "Dinastia Han Cinese", "stile_immagine": ( "Traditional Chinese art style, with ink wash influences, ornate calligraphy, " "and vibrant silk robe patterns. Use subtle brush strokes and bold reds/golds. " "Designed for clarity in a card game with a distinctly ancient Asian aesthetic." ) }, "Impero Persiano": { "nome": "Impero Persiano", "stile_immagine": ( "Intricate Persian miniature style, lavish details, floral ornaments, " "and strong jewel tones like turquoise, gold, and purple. Stylized silhouettes " "in a rich, decorative composition suited for card art." ) }, "Impero Ottomano": { "nome": "Impero Ottomano", "stile_immagine": ( "Ottoman illuminated manuscript style, featuring ornate arabesque borders, " "rich gold leaf, and deep sapphire or emerald backgrounds. " "Figures with flowing robes and turbans, capturing courtly splendor." ) }, "Maya": { "nome": "Maya", "stile_immagine": ( "Mesoamerican style with stylized glyphs, stepped pyramids, and bright colors. " "Incorporate traditional motifs of jaguars and feathers in a decorative, yet readable card layout." ) }, "Vichinghi": { "nome": "Vichinghi", "stile_immagine": ( "Norse-inspired style, with knotwork borders, runic inscriptions, and rugged, " "weathered textures. Use earthy colors and references to Viking longships, " "mythology, and wooden carvings. Balanced for a legible card game design." ) }, "Pirati": { "nome": "Pirati", "stile_immagine": ( "A dynamic and adventurous style inspired by leggende dei mari e pirati romantici. " "Immagini di navi in tempesta, mappe del tesoro, e personaggi con bandane e cappelli tricorni. " "Toni marinari, textures consumate dal sale e dall'acqua, e un'atmosfera ribelle ma affascinante, " "perfetta per un gioco di carte che evoca il brivido dell'avventura sul mare." ) }, "Cowboy del Far West": { "nome": "Cowboy del Far West", "stile_immagine": ( "Uno stile che richiama i paesaggi desertici, le praterie sconfinate e i tramonti infuocati. " "Elementi iconici come cappelli da cowboy, revolver e diligenze, uniti a colori terrosi e caldi. " "Una composizione che unisce il romanticismo dell'Ovest selvaggio a un design chiaro e narrativo, " "ideale per illustrare scene di duelli e viaggi avventurosi." ) }, "Steampunk": { "nome": "Steampunk", "stile_immagine": ( "Un'estetica retrofuturistica che fonde l'epoca vittoriana con invenzioni meccaniche. " "Abiti d'epoca, ingranaggi in ottone, macchinari complessi e ambientazioni industriali. " "Colori caldi e metallici, texture invecchiate e dettagli elaborati che trasmettono un'atmosfera " "di mistero e innovazione, perfetti per una carta di gioco che vuole raccontare storie fuori dal comune." ) }, "Alieni": { "nome": "Alieni", "stile_immagine": ( "Un'estetica fantascientifica e surreale, con creature d'aspetto extraterrestre, " "paesaggi cosmici e tecnologie aliene. Combina elementi di luce fluorescente, " "forme organiche e architetture impossibili, creando un'atmosfera misteriosa e intrigante. " "Ideale per un gioco di carte che trasporta i giocatori in un universo lontano e pieno di meraviglie." ) }, "Homo Sapiens": { "nome": "Homo Sapiens", "stile_immagine": ( "Un'interpretazione moderna e riflessiva dell'evoluzione umana, con un mix di realismo e " "elementi simbolici che rappresentano la storia e la cultura della nostra specie. " "Utilizza toni naturali, texture ispirate alla materia organica e dettagli che richiamano " "l'arte preistorica e contemporanea, per creare un'immagine che unisce il passato remoto al presente." ) },}
# Definizione dello schema Pydantic per un personaggioclass Character(BaseModel):9 unmodified linesclass CharactersResponse(BaseModel): personaggi: list[Character]
def generate_story(character: Character, nome_ambientazione): def generate_story(character: Character, nome_ambientazione, creativita): response = clientOpenAI.chat.completions.create( model='gemini-2.0-flash-thinking-exp-01-21', n=1, stream=True, temperature=creativita, messages=[ {"role": "system", "content": f"Tu sei un creatore di giochi di ruolo a CARTE. Crea un regolamento per un gioco di ruolo sul {nome_ambientazione} sulla base dei personaggi che ti fornirò"}, {13 unmodified lines print(story) return story
def generate_ai(num_personaggi, nome_ambientazione):def generate_ai(num_personaggi, nome_ambientazione, creativita): # Costruzione del prompt in italiano per generare i personaggi prompt = ( f"Genera {num_personaggi} personaggi per un gioco di ruolo a carte ambientato nel {nome_ambientazione}. "7 unmodified lines {"role": "system", "content": f"Sei un assistente utile per la generazione di personaggi per un gioco di RUOLO sul {nome_ambientazione}."}, {"role": "user", "content": prompt}, ], temperature=creativita, response_format=CharactersResponse, ) characters_response = completion.choices[0].message.parsed25 unmodified lines
def generate_images(character: Character, stile_immagine, num_immagini): # Lista per salvare le immagini generate come tuple (nome_file, bytes) prompt = f"{character.english_description} {stile_immagine}" prompt = f"{character.english_description} {stile_immagine}. (INSERT TEXT NAME = {character.nome})" images_bytes_list = [] if character.nome != "": st.subheader(f"{character.nome} 🦸♂️")25 unmodified lines stile_immagine = st.sidebar.text_area("Stile Immagine", stile_default, disabled=False) auto = False prompt_input = st.sidebar.text_input("Prompt Immagine (in inglese)", value="Soldier", disabled=auto) auto = st.sidebar.toggle(label= 'Generazione automatica') auto = st.sidebar.toggle(label= 'Generazione automatica', value = True) num_personaggi = st.sidebar.slider("Personaggi", min_value=1, max_value=30, value=5, disabled=not auto) num_immagini = st.sidebar.slider("Variazioni Immagini", min_value=1, max_value=6, value=2) creativita = st.sidebar.slider("Creativita", min_value=0.1, max_value=1.0, value=0.8, step=0.1) submit_button = st.sidebar.button(label="Genera Immagine", type="primary", use_container_width=True) st.write("Forgia il tuo **destino nell'Impero**: crea, combatti e domina con nel più grande gioco di ruolo a carte generato dall'AI") if submit_button:2 unmodified lines return if auto: with st.spinner('Generazione Personaggi'): characters = generate_ai(num_personaggi, nome_ambientazione) characters = generate_ai(num_personaggi, nome_ambientazione, creativita) st.subheader('Personaggi 🎭') df = pd.DataFrame([{k: v for k, v in character.model_dump().items() if k != "english_description"} for character in characters.personaggi]) st.dataframe(df, hide_index=True) st.divider() generate_story(characters, nome_ambientazione) generate_story(characters, nome_ambientazione, creativita) st.divider() else: characters = CharactersResponse(personaggi=[Character(nome="", classe="Guerriero", forza=10, destrezza=8, intelligenza=6, descrizione="Un forte guerriero", english_description=prompt_input)])app.py+115-75