Spaces:
Runtime error
Runtime error
""" | |
Title : Landing Page of the application | |
@author : Sakshi Tantak | |
""" | |
# Imports | |
import base64 | |
import requests | |
import streamlit as st | |
from filepaths import LOGO_PATH, POSTER_PATH | |
st.set_page_config(page_title = 'Dungeons & Dragons', 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) | |
if 'llm_endpoint' not in st.session_state: | |
st.session_state['llm_endpoint'] = '' | |
if 'stable_diffusion_endpoint' not in st.session_state: | |
st.session_state['stable_diffusion_endpoint'] = '' | |
def add_bg_from_local(image_file): | |
with open(image_file, "rb") as image_file: | |
encoded_string = base64.b64encode(image_file.read()) | |
st.markdown( | |
f""" | |
<style> | |
.stApp {{ | |
image: url(data:image/{"jpeg"};base64,{encoded_string.decode()}); | |
size: auto | |
}} | |
</style> | |
""", | |
unsafe_allow_html=True | |
) | |
def get_api_endpoints(): | |
form = st.form('api-endpoints') | |
with form: | |
llm_endpoint = st.text_input(label = 'LLM Endpoint', | |
value = 'https://643b-34-132-196-118.ngrok-free.app') | |
stable_diffusion_endpoint = form.text_input(label = 'Stable Diffusion Endpoint', | |
value = 'https://643b-34-132-196-118.ngrok-free.app') | |
submitted = st.form_submit_button('Add URLs') | |
if submitted: | |
with st.spinner('Checking if the URLs are valid'): | |
try: | |
llm_response = requests.get(url = llm_endpoint) | |
if llm_response.status_code == 200 and llm_response.text == 'Dungeon Master': | |
st.success('Hurrah! Your LLM endpoint works!') | |
else: | |
st.error('Err! This LLM endpoint is invalid or is not working!') | |
except: | |
st.error('Err! This LLM endpoint is invalid or is not working!') | |
try: | |
sd_response = requests.get(url = stable_diffusion_endpoint) | |
if sd_response.status_code == 200 and sd_response.text == 'Generate Avatar': | |
st.success('Hurrah! Your Stable Diffusion endpoint works!') | |
else: | |
st.error('Err! This Stable Diffusion endpoint is invalid or is not working!') | |
except: | |
st.error('Err! This Stable Diffusion endpoint is invalid or is not working!') | |
return llm_endpoint, stable_diffusion_endpoint | |
return None, None | |
def main(): | |
set_centered_heading('Dungeons & Dragons') | |
placeholder = st.empty() | |
with placeholder: | |
cols = st.columns(2) | |
with cols[0]: | |
st.image(POSTER_PATH) | |
with cols[-1]: | |
llm_endpoint, stable_diffusion_endpoint = get_api_endpoints() | |
if llm_endpoint is not None and stable_diffusion_endpoint is not None: | |
print(llm_endpoint, stable_diffusion_endpoint) | |
st.session_state['llm_endpoint'] = llm_endpoint | |
st.session_state['stable_diffusion_endpoint'] = stable_diffusion_endpoint | |
if __name__ == '__main__': | |
main() |