Spaces:
Runtime error
Runtime error
Update app.py
Browse files19 unmodified lines202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394958 unmodified lines10410510637107108391091101111124311311411511611 unmodified lines12812913061131132133641341351361371 unmodified line1391401417214214314414553 unmodified lines1992002011321331341351361372022032042052061402072082092107 unmodified lines21821922015422122222322422515922622722822919 unmodified lines base_url="https://generativelanguage.googleapis.com/v1beta/openai/")
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." ) }, }
# Definizione dello schema Pydantic per un personaggioclass Character(BaseModel): nome: str 8 unmodified linesclass CharactersResponse(BaseModel): personaggi: list[Character]
def generate_story(character: Character): def generate_story(character: Character, nome_ambientazione): response = clientOpenAI.chat.completions.create( model=MODEL, model='gemini-2.0-flash-thinking-exp-01-21', n=1, stream=True, messages=[ {"role": "system", "content": "Tu sei un creatore di giochi di ruolo a CARTE. Crea un regolamento per un gioco di ruolo sul SACRO ROMANO IMPERO sulla base dei personaggi che ti fornirò"}, {"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ò"}, { "role": "user", "content": f"Ecco i personaggi del gioco di RUOLO a carte. Crea un regolamento!!! {character.model_dump_json()}"11 unmodified lines print(story) return story
def generate_ai(num_personaggi):def generate_ai(num_personaggi, nome_ambientazione): # Costruzione del prompt in italiano per generare i personaggi prompt = ( f"Genera {num_personaggi} personaggi per un gioco di ruolo a carte ambientato nel Sacro Romano Impero. " f"Genera {num_personaggi} personaggi per un gioco di ruolo a carte ambientato nel {nome_ambientazione}. " "Ogni personaggio deve avere i seguenti campi specificati nel modello. " "Restituisci il risultato in formato JSON seguendo lo schema fornito")
1 unmodified line completion = clientOpenAI.beta.chat.completions.parse( model=MODEL, messages=[ {"role": "system", "content": "Sei un assistente utile per la generazione di personaggi per un gioco di RUOLO sul SACRO ROMANO IMPERO."}, {"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}, ], response_format=CharactersResponse,53 unmodified linesdef main(): st.title("Imperium AI 🏰") st.sidebar.header("Impostazioni") stile_default = ("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 ancient Roman mosaics, frescoes, " "and classical sculpture, with a balanced mix of realism and stylization. " "Elegant, decorative card borders with intricate engravings and antique flourishes. " "Designed for a tabletop card game, ensuring clarity, readability, and a visually immersive experience.") selected_ambientazione = st.sidebar.selectbox("Ambientazione", list(ambientazioni.keys()), index=0) stile_default = ambientazioni[selected_ambientazione]["stile_immagine"] nome_ambientazione = ambientazioni[selected_ambientazione]["nome"] 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="Roman Soldier", disabled=auto) prompt_input = st.sidebar.text_input("Prompt Immagine (in inglese)", value="Soldier", disabled=auto) auto = st.sidebar.toggle(label= 'Generazione automatica') 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)7 unmodified lines return if auto: with st.spinner('Generazione Personaggi'): characters = generate_ai(num_personaggi) characters = generate_ai(num_personaggi, nome_ambientazione) 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) generate_story(characters, nome_ambientazione) 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+82-15