-
Notifications
You must be signed in to change notification settings - Fork 24
/
app.py
143 lines (126 loc) · 4.25 KB
/
app.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
134
135
136
137
138
139
140
141
142
143
import streamlit as st
import openai
from datetime import datetime
from streamlit.components.v1 import html
import pandas as pd
import csv
st.set_page_config(page_title="Brainstorming Buddy")
html_temp = """
<div style="background-color:{};padding:1px">
</div>
"""
button = """
<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js" data-name="bmc-button" data-slug="nainiayoub" data-color="#FFDD00" data-emoji="" data-font="Cookie" data-text="Buy me a coffee" data-outline-color="#000000" data-font-color="#000000" data-coffee-color="#ffffff" ></script>
"""
with st.sidebar:
st.markdown("""
# About
Brainstorming Buddy is a helper tool built on GPT-3 to generate ideas on a given topic.
""")
st.markdown(html_temp.format("rgba(55, 53, 47, 0.16)"),unsafe_allow_html=True)
st.markdown("""
# How does it work
Simply enter the topic of interest in the text field below and ideas will be generated.
You can also download the output as txt.
""")
st.markdown(html_temp.format("rgba(55, 53, 47, 0.16)"),unsafe_allow_html=True)
st.markdown("""
Made by [@nainia_ayoub](https://twitter.com/nainia_ayoub)
""",
unsafe_allow_html=True,
)
input_text = None
if 'output' not in st.session_state:
st.session_state['output'] = 0
if st.session_state['output'] <=2:
st.markdown("""
# Brainstorming Buddy
""")
input_text = st.text_input("Brainstorm ideas for", disabled=False, placeholder="What's on your mind?")
st.session_state['output'] = st.session_state['output'] + 1
else:
# input_text = st.text_input("Brainstorm ideas for", disabled=True)
st.info("Thank you! Refresh for more brainstorming💡")
st.markdown('''
<a target="_blank" style="color: black" href="https://twitter.com/intent/tweet?text=I%20just%20used%20the%20Brainstorming%20Buddy%20streamlit%20helper%20tool%20by%20@nainia_ayoub!%0A%0Ahttps://brainstorming-buddy.streamlit.app/">
<button class="btn">
Tweet about this!
</button>
</a>
<style>
.btn{
display: inline-flex;
-moz-box-align: center;
align-items: center;
-moz-box-pack: center;
justify-content: center;
font-weight: 400;
padding: 0.25rem 0.75rem;
border-radius: 0.25rem;
margin: 0px;
line-height: 1.6;
color: #fff;
background-color: #00acee;
width: auto;
user-select: none;
border: 1px solid #00acee;
}
.btn:hover{
color: #00acee;
background-color: #fff;
}
</style>
''',
unsafe_allow_html=True
)
hide="""
<style>
footer{
visibility: hidden;
position: relative;
}
.viewerBadge_container__1QSob{
visibility: hidden;
}
#MainMenu{
visibility: hidden;
}
<style>
"""
st.markdown(hide, unsafe_allow_html=True)
# html(button, height=70, width=220)
# st.markdown(
# """
# <style>
# iframe[width="220"] {
# position: fixed;
# bottom: 60px;
# right: 40px;
# }
# </style>
# """,
# unsafe_allow_html=True,
# )
if input_text:
prompt = "Brainstorm ideas for "+str(input_text)
if prompt:
openai.api_key = st.secrets["openaiKey"]
response = openai.Completion.create(engine="text-davinci-002", prompt=prompt, max_tokens=150)
brainstorming_output = response['choices'][0]['text']
today = datetime.today().strftime('%Y-%m-%d')
topic = "Brainstorming ideas for: "+input_text+"\n@Date: "+str(today)+"\n"+brainstorming_output
st.info(brainstorming_output)
filename = "brainstorming_"+str(today)+".txt"
btn = st.download_button(
label="Download txt",
data=topic,
file_name=filename
)
fields = [input_text, brainstorming_output, str(today)]
# read local csv file
r = pd.read_csv('./data/prompts.csv')
if len(fields)!=0:
with open('./data/prompts.csv', 'a', encoding='utf-8', newline='') as f:
# write to csv file (append mode)
writer = csv.writer(f, delimiter=',', lineterminator='\n')
writer.writerow(fields)