-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfm_poster_public_st.py
133 lines (100 loc) · 2.75 KB
/
fm_poster_public_st.py
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
132
133
"""
Purpose:
BuildOn Poster
"""
import os
# 3rd party imports
import numpy as np
import requests
import streamlit as st
from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
IMAGE_API = os.environ["IMAGE_API"]
TEXT_API = os.environ["TEXT_API"]
st.set_page_config(layout="wide")
def gen_summary(text):
data = {"text": text}
auth_url = TEXT_API.replace("https://", "").replace("/", "")
auth = BotoAWSRequestsAuth(
aws_host=auth_url,
aws_region="us-east-1", # HARDCODED to us-east-1
aws_service="lambda",
)
headers = {
"Content-Type": "application/json",
}
resp = requests.post(TEXT_API, json=data, headers=headers, auth=auth)
# print(resp.json())
return resp.json()["text"]
def gen_image(text):
headers = {
"Content-Type": "application/json",
}
data = {"text": text}
auth_url = IMAGE_API.replace("https://", "").replace("/", "")
auth = BotoAWSRequestsAuth(
aws_host=auth_url,
aws_region="us-east-1", # HARDCODED to us-east-1
aws_service="lambda",
)
resp = requests.post(IMAGE_API, json=data, headers=headers, auth=auth)
# print(resp.json())
return np.array(resp.json()["generated_image"])
def app() -> None:
"""
Purpose:
Controls the app flow
Args:
N/A
Returns:
N/A
"""
col1, col2 = st.columns(2)
article = col1.text_area("Input article", height=900)
styles = col2.multiselect(
"Image Style",
[
"Cloud",
"Pixel Art",
"Landscape",
"Cityscape",
"Futuristic",
"Watercolor",
"Technology",
"Computer",
"Cyberpunk",
"Realistic",
"Retro",
"Abstract",
"Geometric",
"Network",
],
)
if col2.button("Generate"):
with st.spinner("In progress..."):
summary_text = gen_summary(article)
style_string = ""
for style in styles:
style_string += style + " "
summary_image = gen_image(summary_text + style_string)
col2.subheader(summary_text)
col2.image(summary_image)
def main() -> None:
"""
Purpose:
Controls the flow of the streamlit app
Args:
N/A
Returns:
N/A
"""
# Start the streamlit app
st.markdown(
"<h1 style='text-align: center;'>BuildOn Poster</h1>", unsafe_allow_html=True
)
st.markdown(
"<h3 style='text-align: center;'>Sharing your article or idea with the world? Make your content pop with a great tagline and image</h3>",
unsafe_allow_html=True,
)
app()
if __name__ == "__main__":
main()