DungeonMaster / pages /Build_Your_Character.py
pikaduck's picture
fixed wring arg captions to caption in st.image in Build_TYour_Character.py
0613982
"""
Build Your Character
@author : Sakshi Tantk
"""
# Imports
from io import BytesIO
import requests
from PIL import Image
import streamlit as st
from filepaths import LOGO_PATH
st.set_page_config(page_title = 'Build Your Character', layout = 'wide',
page_icon = LOGO_PATH)
def set_centered_heading(text):
st.markdown(f"<h1 style='text-align: center; color: #FF5733;'>{text}</h1>", unsafe_allow_html=True)
set_centered_heading('Build Your Characters')
if 'avatars' not in st.session_state:
st.session_state['avatars'] = {}
def get_parameters():
i = 5
while(i > 0):
form = st.form(f'Character {i+1}')
with form:
character_gender = st.selectbox('Gender', options = ['Male', 'Female', 'Other'])
character_class = st.selectbox('Class',
options = ['barbarian', 'bard', 'cleric',
'druid', 'fighter', 'monk',
'paladin', 'ranger', 'rogue',
'sorcerer', 'warlock', 'wizard'
])
submit_btn = st.form_submit_button('Done')
if submit_btn:
with st.spinner('AI is generating your avatar ;) '):
prompt = f'Generate ONE Dungeons & Dragons character of gender {character_gender} and belonging to the {character_class} class'
response = requests.get(url = st.session_state['stable_diffusion_endpoint'] + '/get-avatar',
json = {'avatar_description' : prompt})
if response.status_code == 200:
image_bytes = BytesIO(response.content)
avatar = Image.open(image_bytes)
st.session_state['avatars'][i+1] = avatar
print(st.session_state['avatars'])
st.image(avatar, caption = character_class)
i-=1
if st.button('Add character?', key = f'add-btn-{i+1}'):
continue
break
if __name__ == '__main__':
get_parameters()