forked from thoppe/alph-the-sacred-river
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
131 lines (83 loc) · 4.31 KB
/
streamlit_app.py
File metadata and controls
131 lines (83 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import streamlit as st
from pathlib import Path
import start_api
from interface import combine_images, encoding_sentences, preprocess_text
app_formal_name = "Ver-Versos"
# Start the app in wide-mode
st.set_page_config(
layout="wide", page_title=app_formal_name, initial_sidebar_state="expanded"
)
st.sidebar.title(app_formal_name)
st.sidebar.markdown("Una WebApp que combina la poesía de [Jorge Caballero](https://www.instagram.com/sosiadeldesasosiego/) con imágenes de [Unsplash.](https://unsplash.com/)")
st.sidebar.markdown("## Instrucciones ##")
# Load presaved poems
known_poems_dest = Path("docs") / "collected_poems"
known_poems = {}
for f_poem in known_poems_dest.glob("*.txt"):
with open(f_poem) as FIN:
title, lines = preprocess_text(FIN.read())
known_poems[title] = lines
print(known_poems.keys())
# Select a starting poem and display the choices in the sidebar
default_poem = "En mi pequeño mundo lleno de nada"
poem_list = list(known_poems.keys())
poem_choice = st.sidebar.selectbox(
"Elige uno de los poemas del siguiente menú desplegable", poem_list, index=poem_list.index(default_poem)
)
lines = known_poems[poem_choice]
# If the user has a custom poem, use it here
with st.beta_expander("Personaliza el texto del poema (da clic aquí)"):
text_input = st.text_area(
"Edita (o pega) el poema aquí, una línea por set de imágenes. La primera línea será el título. Oprime [Control+Enter] para procesar.",
value="\n".join([poem_choice] + lines),
)
poem_choice, lines = preprocess_text(text_input)
# Run the selected poem through the model
results = encoding_sentences(lines)
st.title(poem_choice)
#st.sidebar.markdown("-----------------------------------")
st.sidebar.header("Autores")
st.sidebar.markdown("### Travis Hoppe (Metasemantic) (Código base) ###")
st.sidebar.markdown('[![metasemantic]\
(https://img.shields.io/badge/Github-@thoppe-metasemantic.svg?colorA=gray&colorB=dodgerblue&logo=github)]\
(https://github.com/thoppe)')
st.sidebar.markdown('[![metasemantic]\
(https://img.shields.io/badge/Twitter-@metasemantic-metasemantic.svg?colorA=gray&colorB=dodgerblue&logo=twitter)]\
(https://twitter.com/metasemantic/)')
st.sidebar.markdown("### JECaballeroR (sosiadeldesasosiego) (Código y poemas) ###")
st.sidebar.markdown('[![JECaballeroR]\
(https://img.shields.io/badge/Github-@JECaballeroR-JECaballeroR.svg?colorA=gray&colorB=dodgerblue&logo=github)]\
(https://github.com/JECaballeroR)')
st.sidebar.markdown('[![Sosia del desasosiego]\
(https://img.shields.io/badge/Instagram-@Sosiadeldesasosiego-JECaballeroR.svg?colorA=gray&colorB=pink&logo=instagram)]\
(https://www.instagram.com/sosiadeldesasosiego/)')
st.sidebar.markdown('[![BMAC_JECaballeroR]\
(https://img.shields.io/static/v1?label=BuyMeACoffee&message=JECaballeroR&color=yellow&logo=buy-me-a-coffee)]\
(https://www.buymeacoffee.com/kIOTtHe)')
# Show the credits for each photo in an expandable sidebar
credits = []
for k, row in enumerate(results):
line = row["text"]
st.markdown(f"## *{line}*")
grid = combine_images(row["unsplashIDs"])
credits.append(f"*{line}*")
for image_idx in row["unsplashIDs"]:
source_url = f"https://unsplash.com/photos/{image_idx}"
credit = f"[{source_url}]({source_url})"
credits.append(credit)
credits.append("\n")
# caption = ', '.join([f"{x:0.0f}" for x in row['scores']])
st.image(grid, use_column_width=True)
st.markdown(
f"{app_formal_name} "
f"combina poemas e imágenes [CLIP](https://openai.com/blog/clip) de OpenAI. "
f"Las imágenes se obtienen de Unsplash [landscape dataset](https://github.com/unsplash/datasets) "
"y fotos destacadas, con créditos al final de la página."
)
st.markdown(
"Adaptado con amor 💙 del proyecto [alph-the-sacred-river](https://github.com/thoppe/alph-the-sacred-river), por [@metasemantic](https://twitter.com/metasemantic/status/1349446585952989186)"
)
with st.beta_expander("Créditos de las imágenes utilizadas:"):
st.markdown("Estructura de los créditos: ")
st.markdown("** Linea del poema ** - Link al las imágenes usadas")
st.markdown("\n".join(credits))