import streamlit as st from config import Config from diffusion_image import generate_image_from_text from t5_summary import generate_summary st.write(''' # Poem2Pic: What picture does your poem paint? Poetry is food for the soul. An image is worth a thousand words. With Poem2Pic, generate an image based on a very short summary of your poem! ''') footer = """ """ st.markdown(footer, unsafe_allow_html=True) preload_text = '' try: with open('examples/old_pond.txt', 'r', encoding='utf8') as in_file: preload_text = in_file.read().strip() except Exception: pass poem = st.text_area( f'''**Type or copy-paste a poem or start off with the following haiku (max. {Config.LLM_MAX_INPUT_LENGTH} characters will be considered):**''', preload_text ) if st.button('Generate image'): progress_text = 'Summarizing the poem...give it a moment' progress_bar = st.progress(0, text=progress_text) poem = poem.strip() input_length = len(poem) if input_length > 0: print(poem) target_length = min(input_length, Config.LLM_MAX_INPUT_LENGTH) summary = generate_summary(poem[:target_length]) print(f'Summary: {summary}') st.write(f'''Summary: {summary}''') progress_bar.progress(10, text='Generating image...need a few more minutes') image = generate_image_from_text(summary) progress_bar.progress(100, text='Done!') st.image(image, caption=summary) st.info('Tip: Right-click on the image to save it')