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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ----------------------Importing libraries----------------------
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
from streamlit_pills import pills
|
5 |
+
import pandas as pd
|
6 |
+
import openai
|
7 |
+
|
8 |
+
# Imports for AgGrid
|
9 |
+
from st_aggrid import AgGrid, GridUpdateMode, JsCode
|
10 |
+
from st_aggrid.grid_options_builder import GridOptionsBuilder
|
11 |
+
|
12 |
+
# ----------------------Importing utils.py----------------------
|
13 |
+
|
14 |
+
# For Snowflake (from Tony's utils.py)
|
15 |
+
import io
|
16 |
+
from utils import (
|
17 |
+
connect_to_snowflake,
|
18 |
+
load_data_to_snowflake,
|
19 |
+
load_data_to_postgres,
|
20 |
+
connect_to_postgres,
|
21 |
+
)
|
22 |
+
|
23 |
+
# ----------------------Page config--------------------------------------
|
24 |
+
|
25 |
+
st.set_page_config(page_title="GPT3 Dataset Generator", page_icon="π€")
|
26 |
+
|
27 |
+
# ----------------------Sidebar section--------------------------------
|
28 |
+
|
29 |
+
# st.image(
|
30 |
+
# "Gifs/header.gif",
|
31 |
+
# )
|
32 |
+
|
33 |
+
st.image("Gifs/boat_new.gif")
|
34 |
+
|
35 |
+
c30, c31, c32 = st.columns([0.2, 0.1, 3])
|
36 |
+
|
37 |
+
with c30:
|
38 |
+
|
39 |
+
st.caption("")
|
40 |
+
|
41 |
+
st.image("openai.png", width=60)
|
42 |
+
|
43 |
+
with c32:
|
44 |
+
|
45 |
+
st.title("GPT3 Dataset Generator")
|
46 |
+
|
47 |
+
st.write(
|
48 |
+
"This app generates datasets using GPT3. It was created for the βοΈ Snowflake Snowvation Hackathon"
|
49 |
+
)
|
50 |
+
|
51 |
+
tabMain, tabInfo, tabTo_dos = st.tabs(["Main", "Info", "To-do's"])
|
52 |
+
|
53 |
+
with tabInfo:
|
54 |
+
st.write("")
|
55 |
+
st.write("")
|
56 |
+
|
57 |
+
st.subheader("π€ What is GPT-3?")
|
58 |
+
st.markdown(
|
59 |
+
"[GPT-3](https://en.wikipedia.org/wiki/GPT-3) is a large language generation model developed by [OpenAI](https://openai.com/) that can generate human-like text. It has a capacity of 175 billion parameters and is trained on a vast dataset of internet text. It can be used for tasks such as language translation, chatbot language generation, and content generation etc."
|
60 |
+
)
|
61 |
+
|
62 |
+
st.subheader("π What is Streamlit?")
|
63 |
+
st.markdown(
|
64 |
+
"[Streamlit](https://streamlit.io) is an open-source Python library that allows users to create interactive, web-based data visualization and machine learning applications without the need for extensive web development knowledge"
|
65 |
+
)
|
66 |
+
|
67 |
+
st.write("---")
|
68 |
+
|
69 |
+
st.subheader("π Resources")
|
70 |
+
st.markdown(
|
71 |
+
"""
|
72 |
+
- OpenAI
|
73 |
+
- [OpenAI Playground](https://beta.openai.com/playground)
|
74 |
+
- [OpenAI Documentation](https://beta.openai.com/docs)
|
75 |
+
- Streamlit
|
76 |
+
- [Documentation](https://docs.streamlit.io/)
|
77 |
+
- [Gallery](https://streamlit.io/gallery)
|
78 |
+
- [Cheat sheet](https://docs.streamlit.io/library/cheatsheet)
|
79 |
+
- [Book](https://www.amazon.com/dp/180056550X) (Getting Started with Streamlit for Data Science)
|
80 |
+
- Deploy your apps using [Streamlit Community Cloud](https://streamlit.io/cloud) in just a few clicks
|
81 |
+
"""
|
82 |
+
)
|
83 |
+
|
84 |
+
with tabTo_dos:
|
85 |
+
|
86 |
+
with st.expander("To-do", expanded=True):
|
87 |
+
st.write(
|
88 |
+
"""
|
89 |
+
- [p2] Currently, the results are displayed even if the submit button isn't pressed.
|
90 |
+
- [p2] There is still an issue with the index where the first element from the JSON is not being displayed.
|
91 |
+
- [Post Hackathon] To limit the number of API calls and costs, let's cap the maximum number - of results to 5. Alternatively, we can consider removing the free API key.
|
92 |
+
|
93 |
+
"""
|
94 |
+
)
|
95 |
+
st.write("")
|
96 |
+
|
97 |
+
with st.expander("Done", expanded=True):
|
98 |
+
st.write(
|
99 |
+
"""
|
100 |
+
- [p2] Check if the Json file is working
|
101 |
+
- [p2] On Github, remove any unused images and GIFs.
|
102 |
+
- [p1] Add that for postgress - localhost is required
|
103 |
+
- [p2] Rename the CSV and JSON as per the st-pills variable
|
104 |
+
- [p2] Change the color of the small arrow
|
105 |
+
- [p1] Adjust the size of the Gifs
|
106 |
+
- Add a streamlit badge in the `ReadMe` file
|
107 |
+
- Add the message "Please enter your API key or choose the `Free Key` option."
|
108 |
+
- Include a `ReadMe` file
|
109 |
+
- Add a section for the Snowflake credentials
|
110 |
+
- Remove password from the Python file
|
111 |
+
- Add screenshots to the `ReadMe` file
|
112 |
+
- Include forms in the snowflake postgres section
|
113 |
+
- Remove the hashed code in the Python file
|
114 |
+
- Include additional information in the 'info' tab
|
115 |
+
- p1] Fix the download issue by sorting it via session state
|
116 |
+
- [p1] Make the dataframe from this app editable
|
117 |
+
- Add more gifs to the app
|
118 |
+
- Change the color scheme to Snowflake Blue
|
119 |
+
- Include a section for Snowflake credentials
|
120 |
+
- Change the colors of the arrows, using this tool (https://lottiefiles.com/lottie-to-gif/convert)
|
121 |
+
- Try new prompts and implement the best ones
|
122 |
+
- Add a config file for the color scheme
|
123 |
+
- Include an option menu using this tool (https://github.com/victoryhb/streamlit-option-menu)
|
124 |
+
- Display a message when the API key is not provided
|
125 |
+
- Fix the arrow and rearrange the layout for the API key message
|
126 |
+
- Check and improve the quality of the prompt output
|
127 |
+
- Send the app to Tony and upload it to GitHub
|
128 |
+
- Re-arrange the data on the sidebar
|
129 |
+
- Change the colors of both gifs to match the overall color scheme
|
130 |
+
- Add context about the app being part of the snowvation project
|
131 |
+
- Add a button to convert the data to JSON format
|
132 |
+
- Include the Snowflake logo
|
133 |
+
- Add a submit button to block API calls unless pressed
|
134 |
+
- Add a tab with additional information
|
135 |
+
- Resize the columns in the st.form section
|
136 |
+
- Add the ability to add the dataset to Snowflake
|
137 |
+
- Create a section with pills, showcasing examples
|
138 |
+
- Change the main emoji
|
139 |
+
- Change the emoji in the tab (page_icon)
|
140 |
+
- [INFO] Sort out the issue with credits
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
"""
|
145 |
+
)
|
146 |
+
st.write("")
|
147 |
+
|
148 |
+
with st.expander("Not needed", expanded=True):
|
149 |
+
st.write(
|
150 |
+
"""
|
151 |
+
- Check index issue in readcsv (not an issue as I've changed the script)
|
152 |
+
- Add the mouse gif (doesn't fit)
|
153 |
+
- Ask Lukas - automatically resize the columns of a DataFrame
|
154 |
+
"""
|
155 |
+
)
|
156 |
+
st.write("")
|
157 |
+
|
158 |
+
st.write("")
|
159 |
+
st.write("")
|
160 |
+
st.write("")
|
161 |
+
|
162 |
+
|
163 |
+
with tabMain:
|
164 |
+
|
165 |
+
key_choice = st.sidebar.radio(
|
166 |
+
"",
|
167 |
+
(
|
168 |
+
"Your Key",
|
169 |
+
"Free Key (capped)",
|
170 |
+
),
|
171 |
+
horizontal=True,
|
172 |
+
)
|
173 |
+
|
174 |
+
if key_choice == "Your Key":
|
175 |
+
|
176 |
+
API_Key = st.sidebar.text_input(
|
177 |
+
"First, enter your OpenAI API key", type="password"
|
178 |
+
)
|
179 |
+
|
180 |
+
elif key_choice == "Free Key (capped)":
|
181 |
+
|
182 |
+
API_Key = st.secrets["API_KEY"]
|
183 |
+
|
184 |
+
image_arrow = st.sidebar.image(
|
185 |
+
"Gifs/blue_grey_arrow.gif",
|
186 |
+
)
|
187 |
+
|
188 |
+
if key_choice == "Free Key (capped)":
|
189 |
+
|
190 |
+
image_arrow.empty()
|
191 |
+
|
192 |
+
else:
|
193 |
+
|
194 |
+
st.write("")
|
195 |
+
|
196 |
+
st.sidebar.caption(
|
197 |
+
"No OpenAI API key? Get yours [here!](https://openai.com/blog/api-no-waitlist/)"
|
198 |
+
)
|
199 |
+
pass
|
200 |
+
|
201 |
+
st.write("")
|
202 |
+
|
203 |
+
c30, c31, c32 = st.columns([0.2, 0.1, 3])
|
204 |
+
|
205 |
+
st.subheader("β Build your dataset")
|
206 |
+
|
207 |
+
example = pills(
|
208 |
+
"",
|
209 |
+
[
|
210 |
+
"Sci-fi Movies",
|
211 |
+
"Animals",
|
212 |
+
"Pop Songs",
|
213 |
+
"POTUS's Twitter",
|
214 |
+
"Blank",
|
215 |
+
],
|
216 |
+
[
|
217 |
+
"πΏ",
|
218 |
+
"π",
|
219 |
+
"π΅",
|
220 |
+
"πΊπΈ",
|
221 |
+
"π»",
|
222 |
+
],
|
223 |
+
label_visibility="collapsed",
|
224 |
+
)
|
225 |
+
|
226 |
+
if "counter" not in st.session_state:
|
227 |
+
st.session_state.counter = 0
|
228 |
+
|
229 |
+
def increment():
|
230 |
+
st.session_state.counter += 1
|
231 |
+
|
232 |
+
if example == "Sci-fi Movies":
|
233 |
+
|
234 |
+
with st.form("my_form"):
|
235 |
+
|
236 |
+
text_input = st.text_input(
|
237 |
+
"What is the topic of your dataset?", value="Sci-fi movies"
|
238 |
+
)
|
239 |
+
|
240 |
+
col1, col2, col3 = st.columns(3, gap="small")
|
241 |
+
|
242 |
+
with col1:
|
243 |
+
column_01 = st.text_input("1st column", value="Title")
|
244 |
+
|
245 |
+
with col2:
|
246 |
+
column_02 = st.text_input("2nd column", value="Year")
|
247 |
+
|
248 |
+
with col3:
|
249 |
+
column_03 = st.text_input("3rd column", value="PG rating")
|
250 |
+
|
251 |
+
col1, col2 = st.columns(2, gap="medium")
|
252 |
+
|
253 |
+
with col1:
|
254 |
+
number = st.number_input(
|
255 |
+
"How many rows do you want?",
|
256 |
+
value=5,
|
257 |
+
min_value=1,
|
258 |
+
max_value=20,
|
259 |
+
step=5,
|
260 |
+
help="The maximum number of rows is 20.",
|
261 |
+
)
|
262 |
+
|
263 |
+
with col2:
|
264 |
+
engine = st.radio(
|
265 |
+
"GPT3 engine",
|
266 |
+
(
|
267 |
+
"Davinci",
|
268 |
+
"Curie",
|
269 |
+
"Babbage",
|
270 |
+
),
|
271 |
+
horizontal=True,
|
272 |
+
help="Davinci is the most powerful engine, but it's also the slowest. Curie is the fastest, but it's also the least powerful. Babbage is somewhere in the middle.",
|
273 |
+
)
|
274 |
+
|
275 |
+
if engine == "Davinci":
|
276 |
+
engine = "davinci-instruct-beta-v3"
|
277 |
+
elif engine == "Curie":
|
278 |
+
engine = "curie-instruct-beta-v2"
|
279 |
+
elif engine == "Babbage":
|
280 |
+
engine = "babbage-instruct-beta"
|
281 |
+
|
282 |
+
st.write("")
|
283 |
+
|
284 |
+
submitted = st.form_submit_button("Build my dataset! β¨", on_click=increment)
|
285 |
+
|
286 |
+
elif example == "Animals":
|
287 |
+
|
288 |
+
with st.form("my_form"):
|
289 |
+
|
290 |
+
text_input = st.text_input(
|
291 |
+
"What is the topic of your dataset?", value="Fastest animals on earth"
|
292 |
+
)
|
293 |
+
|
294 |
+
col1, col2, col3 = st.columns(3, gap="small")
|
295 |
+
|
296 |
+
with col1:
|
297 |
+
column_01 = st.text_input("1st column", value="Animal")
|
298 |
+
|
299 |
+
with col2:
|
300 |
+
column_02 = st.text_input("2nd column", value="Speed")
|
301 |
+
|
302 |
+
with col3:
|
303 |
+
column_03 = st.text_input("3rd column", value="Weight")
|
304 |
+
|
305 |
+
col1, col2 = st.columns(2, gap="medium")
|
306 |
+
|
307 |
+
with col1:
|
308 |
+
number = st.number_input(
|
309 |
+
"How many rows do you want?",
|
310 |
+
value=5,
|
311 |
+
min_value=1,
|
312 |
+
max_value=20,
|
313 |
+
step=5,
|
314 |
+
help="The maximum number of rows is 50.",
|
315 |
+
)
|
316 |
+
|
317 |
+
with col2:
|
318 |
+
engine = st.radio(
|
319 |
+
"GPT3 engine",
|
320 |
+
(
|
321 |
+
"Davinci",
|
322 |
+
"Curie",
|
323 |
+
"Babbage",
|
324 |
+
),
|
325 |
+
horizontal=True,
|
326 |
+
help="Davinci is the most powerful engine, but it's also the slowest. Curie is the fastest, but it's also the least powerful. Babbage is somewhere in the middle.",
|
327 |
+
)
|
328 |
+
|
329 |
+
if engine == "Davinci":
|
330 |
+
engine = "davinci-instruct-beta-v3"
|
331 |
+
elif engine == "Curie":
|
332 |
+
engine = "curie-instruct-beta-v2"
|
333 |
+
elif engine == "Babbage":
|
334 |
+
engine = "babbage-instruct-beta"
|
335 |
+
|
336 |
+
st.write("")
|
337 |
+
|
338 |
+
submitted = st.form_submit_button("Build my dataset! β¨", on_click=increment)
|
339 |
+
|
340 |
+
elif example == "Stocks":
|
341 |
+
|
342 |
+
with st.form("my_form"):
|
343 |
+
|
344 |
+
text_input = st.text_input(
|
345 |
+
"What is the topic of your dataset?", value="Stocks"
|
346 |
+
)
|
347 |
+
|
348 |
+
col1, col2, col3 = st.columns(3, gap="small")
|
349 |
+
|
350 |
+
with col1:
|
351 |
+
column_01 = st.text_input("1st column", value="Ticker")
|
352 |
+
|
353 |
+
with col2:
|
354 |
+
column_02 = st.text_input("2nd column", value="Price")
|
355 |
+
|
356 |
+
with col3:
|
357 |
+
column_03 = st.text_input("3rd column", value="Exchange")
|
358 |
+
|
359 |
+
col1, col2 = st.columns(2, gap="medium")
|
360 |
+
|
361 |
+
with col1:
|
362 |
+
number = st.number_input(
|
363 |
+
"How many rows do you want?",
|
364 |
+
value=5,
|
365 |
+
min_value=1,
|
366 |
+
max_value=20,
|
367 |
+
step=5,
|
368 |
+
help="The maximum number of rows is 50.",
|
369 |
+
)
|
370 |
+
|
371 |
+
with col2:
|
372 |
+
engine = st.radio(
|
373 |
+
"GPT3 engine",
|
374 |
+
(
|
375 |
+
"Davinci",
|
376 |
+
"Curie",
|
377 |
+
"Babbage",
|
378 |
+
),
|
379 |
+
horizontal=True,
|
380 |
+
help="Davinci is the most powerful engine, but it's also the slowest. Curie is the fastest, but it's also the least powerful. Babbage is somewhere in the middle.",
|
381 |
+
)
|
382 |
+
|
383 |
+
if engine == "Davinci":
|
384 |
+
engine = "davinci-instruct-beta-v3"
|
385 |
+
elif engine == "Curie":
|
386 |
+
engine = "curie-instruct-beta-v2"
|
387 |
+
elif engine == "Babbage":
|
388 |
+
engine = "babbage-instruct-beta"
|
389 |
+
|
390 |
+
st.write("")
|
391 |
+
|
392 |
+
submitted = st.form_submit_button("Build my dataset! β¨", on_click=increment)
|
393 |
+
|
394 |
+
elif example == "POTUS's Twitter":
|
395 |
+
|
396 |
+
with st.form("my_form"):
|
397 |
+
|
398 |
+
text_input = st.text_input(
|
399 |
+
"What is the topic of your dataset?", value="POTUS's Twitter accounts"
|
400 |
+
)
|
401 |
+
|
402 |
+
col1, col2, col3 = st.columns(3, gap="small")
|
403 |
+
|
404 |
+
with col1:
|
405 |
+
column_01 = st.text_input("1st column", value="Name")
|
406 |
+
|
407 |
+
with col2:
|
408 |
+
column_02 = st.text_input("2nd column", value="Twitter handle")
|
409 |
+
|
410 |
+
with col3:
|
411 |
+
column_03 = st.text_input("3rd column", value="# of followers")
|
412 |
+
|
413 |
+
col1, col2 = st.columns(2, gap="medium")
|
414 |
+
|
415 |
+
with col1:
|
416 |
+
number = st.number_input(
|
417 |
+
"How many rows do you want?",
|
418 |
+
value=5,
|
419 |
+
min_value=1,
|
420 |
+
max_value=20,
|
421 |
+
step=5,
|
422 |
+
help="The maximum number of rows is 50.",
|
423 |
+
)
|
424 |
+
|
425 |
+
with col2:
|
426 |
+
engine = st.radio(
|
427 |
+
"GPT3 engine",
|
428 |
+
(
|
429 |
+
"Davinci",
|
430 |
+
"Curie",
|
431 |
+
"Babbage",
|
432 |
+
),
|
433 |
+
horizontal=True,
|
434 |
+
help="Davinci is the most powerful engine, but it's also the slowest. Curie is the fastest, but it's also the least powerful. Babbage is somewhere in the middle.",
|
435 |
+
)
|
436 |
+
|
437 |
+
if engine == "Davinci":
|
438 |
+
engine = "davinci-instruct-beta-v3"
|
439 |
+
elif engine == "Curie":
|
440 |
+
engine = "curie-instruct-beta-v2"
|
441 |
+
elif engine == "Babbage":
|
442 |
+
engine = "babbage-instruct-beta"
|
443 |
+
|
444 |
+
st.write("")
|
445 |
+
|
446 |
+
submitted = st.form_submit_button("Build my dataset! β¨")
|
447 |
+
|
448 |
+
elif example == "Pop Songs":
|
449 |
+
|
450 |
+
with st.form("my_form"):
|
451 |
+
|
452 |
+
text_input = st.text_input(
|
453 |
+
"What is the topic of your dataset?",
|
454 |
+
value="Most famous songs of all time",
|
455 |
+
)
|
456 |
+
|
457 |
+
col1, col2, col3 = st.columns(3, gap="small")
|
458 |
+
|
459 |
+
with col1:
|
460 |
+
column_01 = st.text_input("1st column", value="Song")
|
461 |
+
|
462 |
+
with col2:
|
463 |
+
column_02 = st.text_input("2nd column", value="Artist")
|
464 |
+
|
465 |
+
with col3:
|
466 |
+
column_03 = st.text_input("3rd column", value="Genre")
|
467 |
+
|
468 |
+
col1, col2 = st.columns(2, gap="medium")
|
469 |
+
|
470 |
+
with col1:
|
471 |
+
number = st.number_input(
|
472 |
+
"How many rows do you want?",
|
473 |
+
value=5,
|
474 |
+
min_value=1,
|
475 |
+
max_value=20,
|
476 |
+
step=5,
|
477 |
+
help="The maximum number of rows is 50.",
|
478 |
+
)
|
479 |
+
|
480 |
+
with col2:
|
481 |
+
engine = st.radio(
|
482 |
+
"GPT3 engine",
|
483 |
+
(
|
484 |
+
"Davinci",
|
485 |
+
"Curie",
|
486 |
+
"Babbage",
|
487 |
+
),
|
488 |
+
horizontal=True,
|
489 |
+
help="Davinci is the most powerful engine, but it's also the slowest. Curie is the fastest, but it's also the least powerful. Babbage is somewhere in the middle.",
|
490 |
+
)
|
491 |
+
|
492 |
+
if engine == "Davinci":
|
493 |
+
engine = "davinci-instruct-beta-v3"
|
494 |
+
elif engine == "Curie":
|
495 |
+
engine = "curie-instruct-beta-v2"
|
496 |
+
elif engine == "Babbage":
|
497 |
+
engine = "babbage-instruct-beta"
|
498 |
+
|
499 |
+
st.write("")
|
500 |
+
|
501 |
+
submitted = st.form_submit_button("Build my dataset! β¨")
|
502 |
+
|
503 |
+
elif example == "Blank":
|
504 |
+
|
505 |
+
with st.form("my_form"):
|
506 |
+
|
507 |
+
text_input = st.text_input("What is the topic of your dataset?", value="")
|
508 |
+
|
509 |
+
col1, col2, col3 = st.columns(3, gap="small")
|
510 |
+
|
511 |
+
with col1:
|
512 |
+
column_01 = st.text_input("1st column", value="")
|
513 |
+
|
514 |
+
with col2:
|
515 |
+
column_02 = st.text_input("2nd column", value="")
|
516 |
+
|
517 |
+
with col3:
|
518 |
+
column_03 = st.text_input("3rd column", value="")
|
519 |
+
|
520 |
+
col1, col2 = st.columns(2, gap="medium")
|
521 |
+
|
522 |
+
with col1:
|
523 |
+
number = st.number_input(
|
524 |
+
"How many rows do you want?",
|
525 |
+
value=5,
|
526 |
+
min_value=1,
|
527 |
+
max_value=20,
|
528 |
+
step=5,
|
529 |
+
help="The maximum number of rows is 50.",
|
530 |
+
)
|
531 |
+
|
532 |
+
with col2:
|
533 |
+
engine = st.radio(
|
534 |
+
"GPT3 engine",
|
535 |
+
(
|
536 |
+
"Davinci",
|
537 |
+
"Curie",
|
538 |
+
"Babbage",
|
539 |
+
),
|
540 |
+
horizontal=True,
|
541 |
+
help="Davinci is the most powerful engine, but it's also the slowest. Curie is the fastest, but it's also the least powerful. Babbage is somewhere in the middle.",
|
542 |
+
)
|
543 |
+
|
544 |
+
if engine == "Davinci":
|
545 |
+
engine = "davinci-instruct-beta-v3"
|
546 |
+
elif engine == "Curie":
|
547 |
+
engine = "curie-instruct-beta-v2"
|
548 |
+
elif engine == "Babbage":
|
549 |
+
engine = "babbage-instruct-beta"
|
550 |
+
|
551 |
+
st.write("")
|
552 |
+
|
553 |
+
submitted = st.form_submit_button("Build my dataset! β¨")
|
554 |
+
|
555 |
+
# ----------------------API key section----------------------------------
|
556 |
+
|
557 |
+
number = number + 1
|
558 |
+
|
559 |
+
if not API_Key and not submitted:
|
560 |
+
|
561 |
+
st.stop()
|
562 |
+
|
563 |
+
if not API_Key and submitted:
|
564 |
+
|
565 |
+
st.info("Please enter your API key or choose the `Free Key` option.")
|
566 |
+
st.stop()
|
567 |
+
|
568 |
+
if st.session_state.counter >= 100:
|
569 |
+
|
570 |
+
pass
|
571 |
+
|
572 |
+
# ----------------------API key section----------------------------------
|
573 |
+
|
574 |
+
if not submitted and st.session_state.counter == 0:
|
575 |
+
|
576 |
+
c30, c31, c32 = st.columns([1, 0.01, 4])
|
577 |
+
|
578 |
+
with c30:
|
579 |
+
|
580 |
+
st.image("Gifs/arrow_small_new.gif")
|
581 |
+
st.caption("")
|
582 |
+
|
583 |
+
with c32:
|
584 |
+
|
585 |
+
st.caption("")
|
586 |
+
st.caption("")
|
587 |
+
|
588 |
+
st.info(
|
589 |
+
"Enter your dataset's criteria and click the button to generate it."
|
590 |
+
)
|
591 |
+
|
592 |
+
st.stop()
|
593 |
+
|
594 |
+
elif st.session_state.counter > 0:
|
595 |
+
|
596 |
+
c30, c31, c32 = st.columns([1, 0.9, 3])
|
597 |
+
|
598 |
+
openai.api_key = API_Key
|
599 |
+
|
600 |
+
# ----------------------API call section----------------------------------
|
601 |
+
|
602 |
+
response = openai.Completion.create(
|
603 |
+
model=engine,
|
604 |
+
prompt=f"Please provide a list of the top {number} {text_input} along with the following information in a three-column spreadsheet: {column_01}, {column_02}, and {column_03}. The columns should be labeled as follows: {column_01} | {column_02} | {column_03}",
|
605 |
+
temperature=0.5,
|
606 |
+
max_tokens=1707,
|
607 |
+
top_p=1,
|
608 |
+
best_of=2,
|
609 |
+
frequency_penalty=0,
|
610 |
+
presence_penalty=0,
|
611 |
+
)
|
612 |
+
|
613 |
+
st.write("___")
|
614 |
+
|
615 |
+
st.subheader("β‘ Check the results")
|
616 |
+
|
617 |
+
with st.expander("See the API Json output"):
|
618 |
+
response
|
619 |
+
|
620 |
+
output_code = response["choices"][0]["text"]
|
621 |
+
|
622 |
+
# ----------------------Dataframe section----------------------------------
|
623 |
+
|
624 |
+
# create pandas DataFrame from string
|
625 |
+
df = pd.read_csv(io.StringIO(output_code), sep="|")
|
626 |
+
# get the number of columns in the dataframe
|
627 |
+
num_columns = len(df.columns)
|
628 |
+
|
629 |
+
# create a list of column names
|
630 |
+
column_names = ["Column {}".format(i) for i in range(1, num_columns + 1)]
|
631 |
+
|
632 |
+
# add the header to the dataframe
|
633 |
+
df.columns = column_names
|
634 |
+
|
635 |
+
# specify the mapping of old column names to new column names
|
636 |
+
column_mapping = {
|
637 |
+
"Column 1": column_01,
|
638 |
+
"Column 2": column_02,
|
639 |
+
"Column 3": column_03,
|
640 |
+
}
|
641 |
+
|
642 |
+
# rename the columns of the dataframe
|
643 |
+
df = df.rename(columns=column_mapping)
|
644 |
+
|
645 |
+
st.write("")
|
646 |
+
|
647 |
+
# ----------------------AgGrid section----------------------------------
|
648 |
+
|
649 |
+
gd = GridOptionsBuilder.from_dataframe(df)
|
650 |
+
gd.configure_pagination(enabled=True)
|
651 |
+
gd.configure_default_column(editable=True, groupable=True)
|
652 |
+
gd.configure_selection(selection_mode="multiple")
|
653 |
+
gridoptions = gd.build()
|
654 |
+
grid_table = AgGrid(
|
655 |
+
df,
|
656 |
+
gridOptions=gridoptions,
|
657 |
+
update_mode=GridUpdateMode.SELECTION_CHANGED,
|
658 |
+
theme="material",
|
659 |
+
)
|
660 |
+
|
661 |
+
# df
|
662 |
+
|
663 |
+
# ----------------------Download section--------------------------------------
|
664 |
+
|
665 |
+
c30, c31, c32, c33 = st.columns([1, 0.01, 1, 2.5])
|
666 |
+
|
667 |
+
with c30:
|
668 |
+
|
669 |
+
@st.cache
|
670 |
+
def convert_df(df):
|
671 |
+
return df.to_csv().encode("utf-8")
|
672 |
+
|
673 |
+
csv = convert_df(df)
|
674 |
+
|
675 |
+
st.download_button(
|
676 |
+
label="Download CSV",
|
677 |
+
data=csv,
|
678 |
+
file_name=f"{example} dataset .csv",
|
679 |
+
mime="text/csv",
|
680 |
+
)
|
681 |
+
|
682 |
+
with c32:
|
683 |
+
|
684 |
+
json_string = df.to_json(orient="records")
|
685 |
+
|
686 |
+
st.download_button(
|
687 |
+
label="Download JSON",
|
688 |
+
data=json_string,
|
689 |
+
file_name="data_set_sample.json",
|
690 |
+
mime="text/csv",
|
691 |
+
)
|
692 |
+
|
693 |
+
st.write("___")
|
694 |
+
|
695 |
+
st.subheader("β’ Load data to Databases")
|
696 |
+
|
697 |
+
# Data to load to database(s)
|
698 |
+
# df = pd.read_csv("philox-testset-1.csv")
|
699 |
+
|
700 |
+
# Get user input for data storage option
|
701 |
+
storage_option = st.radio(
|
702 |
+
"Select data storage option:",
|
703 |
+
(
|
704 |
+
"Snowflake",
|
705 |
+
"PostgreSQL",
|
706 |
+
),
|
707 |
+
horizontal=True,
|
708 |
+
)
|
709 |
+
|
710 |
+
# Get user input for data storage option
|
711 |
+
# Snowflake = st.selectbox(
|
712 |
+
# "Select data storage option:", ["Snowflake", "Snowflake"]
|
713 |
+
# )
|
714 |
+
|
715 |
+
@st.cache(allow_output_mutation=True)
|
716 |
+
def reset_form_fields():
|
717 |
+
user = ""
|
718 |
+
password = ""
|
719 |
+
account = ""
|
720 |
+
warehouse = ""
|
721 |
+
database = ""
|
722 |
+
schema = ""
|
723 |
+
table = ""
|
724 |
+
host = ""
|
725 |
+
port = ""
|
726 |
+
|
727 |
+
if storage_option == "Snowflake":
|
728 |
+
st.subheader("`Enter Snowflake Credentials`π")
|
729 |
+
# Get user input for Snowflake credentials
|
730 |
+
|
731 |
+
with st.form("my_form_db"):
|
732 |
+
|
733 |
+
col1, col2 = st.columns(2, gap="small")
|
734 |
+
|
735 |
+
with col1:
|
736 |
+
user = st.text_input("Username:", value="TONY")
|
737 |
+
with col2:
|
738 |
+
password = st.text_input("Password:", type="password")
|
739 |
+
|
740 |
+
with col1:
|
741 |
+
account = st.text_input("Account:", value="jn27194.us-east4.gcp")
|
742 |
+
with col2:
|
743 |
+
warehouse = st.text_input("Warehouse:", value="NAH")
|
744 |
+
|
745 |
+
with col1:
|
746 |
+
database = st.text_input("Database:", value="SNOWVATION")
|
747 |
+
with col2:
|
748 |
+
schema = st.text_input("Schema:", value="PUBLIC")
|
749 |
+
|
750 |
+
table = st.text_input("Table:")
|
751 |
+
|
752 |
+
st.write("")
|
753 |
+
|
754 |
+
submitted = st.form_submit_button("Load to Snowflake")
|
755 |
+
|
756 |
+
# Load the data to Snowflake
|
757 |
+
if submitted:
|
758 |
+
# if st.button("Load data to Snowflake"):
|
759 |
+
if (
|
760 |
+
user
|
761 |
+
and password
|
762 |
+
and account
|
763 |
+
and warehouse
|
764 |
+
and database
|
765 |
+
and schema
|
766 |
+
and table
|
767 |
+
):
|
768 |
+
conn = connect_to_snowflake(
|
769 |
+
username=user,
|
770 |
+
password=password,
|
771 |
+
account=account,
|
772 |
+
warehouse=warehouse,
|
773 |
+
database=database,
|
774 |
+
schema=schema,
|
775 |
+
)
|
776 |
+
if conn:
|
777 |
+
load_data_to_snowflake(df, conn, table)
|
778 |
+
else:
|
779 |
+
st.warning("Please enter all Snowflake credentials")
|
780 |
+
|
781 |
+
elif storage_option == "PostgreSQL":
|
782 |
+
st.subheader("`Enter PostgreSQL Credentials`π")
|
783 |
+
st.error("Localhost only")
|
784 |
+
# Get user input for PostgreSQL credentials
|
785 |
+
|
786 |
+
with st.form("my_form_db"):
|
787 |
+
|
788 |
+
col1, col2 = st.columns(2, gap="small")
|
789 |
+
|
790 |
+
with col1:
|
791 |
+
user = st.text_input("Username:", value="postgres")
|
792 |
+
with col2:
|
793 |
+
password = st.text_input("Password:", type="password")
|
794 |
+
with col1:
|
795 |
+
host = st.selectbox("Host:", ["localhost", "other"])
|
796 |
+
if host == "other":
|
797 |
+
host = st.text_input("Enter host:")
|
798 |
+
with col2:
|
799 |
+
port = st.text_input("Port:", value="5432")
|
800 |
+
with col1:
|
801 |
+
database = st.text_input("Database:", value="snowvation")
|
802 |
+
with col2:
|
803 |
+
table = st.text_input("Table:")
|
804 |
+
|
805 |
+
st.write("")
|
806 |
+
|
807 |
+
submitted = st.form_submit_button("Load to PostgreSQL")
|
808 |
+
|
809 |
+
# Load the data to PostgreSQL
|
810 |
+
# if st.button("Load data to PostgreSQL"):
|
811 |
+
if submitted:
|
812 |
+
if user and password and host and port and database and table:
|
813 |
+
conn = connect_to_postgres(
|
814 |
+
username=user,
|
815 |
+
password=password,
|
816 |
+
host=host,
|
817 |
+
port=port,
|
818 |
+
database=database,
|
819 |
+
)
|
820 |
+
if conn:
|
821 |
+
load_data_to_postgres(df, conn, table)
|
822 |
+
else:
|
823 |
+
st.warning("Please enter all PostgreSQL credentials and table name")
|
824 |
+
|
825 |
+
# Reset form fields when storage_option changes
|
826 |
+
reset_form_fields()
|