Spaces:
Runtime error
Runtime error
Streamlit UI for landing page & building character ready; supports hard-coded prompt based avatar generation using stable diffusion hosted in colab
Browse files- .gitignore +160 -0
- __init__.py +0 -0
- app.py +87 -0
- assets/__init__.py +0 -0
- assets/logo.jpg +0 -0
- assets/poster.jpg +0 -0
- filepaths.py +9 -0
- pages/Build_Your_Character.py +55 -0
.gitignore
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
__init__.py
ADDED
File without changes
|
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Title : Landing Page of the application
|
3 |
+
@author : Sakshi Tantak
|
4 |
+
"""
|
5 |
+
|
6 |
+
# Imports
|
7 |
+
import base64
|
8 |
+
import requests
|
9 |
+
|
10 |
+
import streamlit as st
|
11 |
+
|
12 |
+
from filepaths import LOGO_PATH, POSTER_PATH
|
13 |
+
|
14 |
+
st.set_page_config(page_title = 'Dungeons & Dragons', layout = 'wide', page_icon = LOGO_PATH)
|
15 |
+
|
16 |
+
def set_centered_heading(text):
|
17 |
+
st.markdown(f"<h1 style='text-align: center; color: #FF5733;'>{text}</h1>", unsafe_allow_html=True)
|
18 |
+
|
19 |
+
if 'llm_endpoint' not in st.session_state:
|
20 |
+
st.session_state['llm_endpoint'] = ''
|
21 |
+
|
22 |
+
if 'stable_diffusion_endpoint' not in st.session_state:
|
23 |
+
st.session_state['stable_diffusion_endpoint'] = ''
|
24 |
+
|
25 |
+
def add_bg_from_local(image_file):
|
26 |
+
with open(image_file, "rb") as image_file:
|
27 |
+
encoded_string = base64.b64encode(image_file.read())
|
28 |
+
st.markdown(
|
29 |
+
f"""
|
30 |
+
<style>
|
31 |
+
.stApp {{
|
32 |
+
image: url(data:image/{"jpeg"};base64,{encoded_string.decode()});
|
33 |
+
size: auto
|
34 |
+
}}
|
35 |
+
</style>
|
36 |
+
""",
|
37 |
+
unsafe_allow_html=True
|
38 |
+
)
|
39 |
+
|
40 |
+
def get_api_endpoints():
|
41 |
+
form = st.form('api-endpoints')
|
42 |
+
with form:
|
43 |
+
llm_endpoint = st.text_input(label = 'LLM Endpoint',
|
44 |
+
value = 'https://643b-34-132-196-118.ngrok-free.app')
|
45 |
+
|
46 |
+
stable_diffusion_endpoint = form.text_input(label = 'Stable Diffusion Endpoint',
|
47 |
+
value = 'https://643b-34-132-196-118.ngrok-free.app')
|
48 |
+
submitted = st.form_submit_button('Add URLs')
|
49 |
+
if submitted:
|
50 |
+
with st.spinner('Checking if the URLs are valid'):
|
51 |
+
try:
|
52 |
+
llm_response = requests.get(url = llm_endpoint)
|
53 |
+
if llm_response.status_code == 200 and llm_response.text == 'Dungeon Master':
|
54 |
+
st.success('Hurrah! Your LLM endpoint works!')
|
55 |
+
else:
|
56 |
+
st.error('Err! This LLM endpoint is invalid or is not working!')
|
57 |
+
except:
|
58 |
+
st.error('Err! This LLM endpoint is invalid or is not working!')
|
59 |
+
|
60 |
+
try:
|
61 |
+
sd_response = requests.get(url = stable_diffusion_endpoint)
|
62 |
+
if sd_response.status_code == 200 and sd_response.text == 'Generate Avatar':
|
63 |
+
st.success('Hurrah! Your Stable Diffusion endpoint works!')
|
64 |
+
else:
|
65 |
+
st.error('Err! This Stable Diffusion endpoint is invalid or is not working!')
|
66 |
+
except:
|
67 |
+
st.error('Err! This Stable Diffusion endpoint is invalid or is not working!')
|
68 |
+
return llm_endpoint, stable_diffusion_endpoint
|
69 |
+
return None, None
|
70 |
+
|
71 |
+
def main():
|
72 |
+
set_centered_heading('Dungeons & Dragons')
|
73 |
+
placeholder = st.empty()
|
74 |
+
with placeholder:
|
75 |
+
cols = st.columns(2)
|
76 |
+
with cols[0]:
|
77 |
+
st.image(POSTER_PATH)
|
78 |
+
|
79 |
+
with cols[-1]:
|
80 |
+
llm_endpoint, stable_diffusion_endpoint = get_api_endpoints()
|
81 |
+
if llm_endpoint is not None and stable_diffusion_endpoint is not None:
|
82 |
+
print(llm_endpoint, stable_diffusion_endpoint)
|
83 |
+
st.session_state['llm_endpoint'] = llm_endpoint
|
84 |
+
st.session_state['stable_diffusion_endpoint'] = stable_diffusion_endpoint
|
85 |
+
|
86 |
+
if __name__ == '__main__':
|
87 |
+
main()
|
assets/__init__.py
ADDED
File without changes
|
assets/logo.jpg
ADDED
![]() |
assets/poster.jpg
ADDED
![]() |
filepaths.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
PROJECT_DIR = os.path.split(__file__)[0]
|
4 |
+
|
5 |
+
print(f'PROJECT_DIR : {PROJECT_DIR}')
|
6 |
+
|
7 |
+
ASSETS = os.path.join(PROJECT_DIR, 'assets')
|
8 |
+
LOGO_PATH = os.path.join(ASSETS, 'logo.jpg')
|
9 |
+
POSTER_PATH = os.path.join(ASSETS, 'poster.jpg')
|
pages/Build_Your_Character.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Build Your Character
|
3 |
+
@author : Sakshi Tantk
|
4 |
+
"""
|
5 |
+
|
6 |
+
# Imports
|
7 |
+
from io import BytesIO
|
8 |
+
import requests
|
9 |
+
from PIL import Image
|
10 |
+
|
11 |
+
import streamlit as st
|
12 |
+
from filepaths import LOGO_PATH
|
13 |
+
|
14 |
+
st.set_page_config(page_title = 'Build Your Character', layout = 'wide',
|
15 |
+
page_icon = LOGO_PATH)
|
16 |
+
|
17 |
+
def set_centered_heading(text):
|
18 |
+
st.markdown(f"<h1 style='text-align: center; color: #FF5733;'>{text}</h1>", unsafe_allow_html=True)
|
19 |
+
|
20 |
+
set_centered_heading('Build Your Characters')
|
21 |
+
|
22 |
+
if 'avatars' not in st.session_state:
|
23 |
+
st.session_state['avatars'] = {}
|
24 |
+
|
25 |
+
def get_parameters():
|
26 |
+
i = 5
|
27 |
+
while(i > 0):
|
28 |
+
form = st.form(f'Character {i+1}')
|
29 |
+
with form:
|
30 |
+
character_gender = st.selectbox('Gender', options = ['Male', 'Female', 'Other'])
|
31 |
+
character_class = st.selectbox('Class',
|
32 |
+
options = ['barbarian', 'bard', 'cleric',
|
33 |
+
'druid', 'fighter', 'monk',
|
34 |
+
'paladin', 'ranger', 'rogue',
|
35 |
+
'sorcerer', 'warlock', 'wizard'
|
36 |
+
])
|
37 |
+
submit_btn = st.form_submit_button('Done')
|
38 |
+
if submit_btn:
|
39 |
+
with st.spinner('AI is generating your avatar ;) '):
|
40 |
+
prompt = f'Generate ONE Dungeons & Dragons character of gender {character_gender} and belonging to the {character_class} class'
|
41 |
+
response = requests.get(url = st.session_state['stable_diffusion_endpoint'] + '/get-avatar',
|
42 |
+
json = {'avatar_description' : prompt})
|
43 |
+
if response.status_code == 200:
|
44 |
+
image_bytes = BytesIO(response.content)
|
45 |
+
avatar = Image.open(image_bytes)
|
46 |
+
st.session_state['avatars'][i+1] = avatar
|
47 |
+
print(st.session_state['avatars'])
|
48 |
+
st.image(avatar, captions = character_class)
|
49 |
+
i-=1
|
50 |
+
if st.button('Add character?', key = f'add-btn-{i+1}'):
|
51 |
+
continue
|
52 |
+
break
|
53 |
+
|
54 |
+
if __name__ == '__main__':
|
55 |
+
get_parameters()
|