Ashhar
commited on
Commit
•
71a2c91
1
Parent(s):
b40d264
feedbacks suggested by Kommuneity
Browse files- app.py +38 -24
- constants.py +13 -14
- pages/popular-stories.py +2 -1
- utils.py +58 -11
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import os
|
3 |
import time
|
4 |
import json
|
@@ -77,7 +78,7 @@ def __isInvalidResponse(response: str):
|
|
77 |
U.pprint("lot of consecutive repeating words")
|
78 |
return True
|
79 |
|
80 |
-
if len(re.findall(r'\n\n', response)) >
|
81 |
U.pprint("lots of paragraphs")
|
82 |
return True
|
83 |
|
@@ -284,6 +285,34 @@ def __generateImage(prompt: str):
|
|
284 |
return result
|
285 |
|
286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
def __resetButtonState():
|
288 |
st.session_state.buttonValue = ""
|
289 |
|
@@ -311,6 +340,9 @@ if "buttonValue" not in st.session_state:
|
|
311 |
if "selectedStory" not in st.session_state:
|
312 |
__resetSelectedStory()
|
313 |
|
|
|
|
|
|
|
314 |
if "isStoryChosen" not in st.session_state:
|
315 |
st.session_state.isStoryChosen = False
|
316 |
|
@@ -341,11 +373,14 @@ for chat in st.session_state.chatHistory:
|
|
341 |
if prompt := (
|
342 |
st.chat_input()
|
343 |
or st.session_state["buttonValue"]
|
344 |
-
or st.session_state["
|
345 |
or st.session_state["startMsg"]
|
346 |
):
|
347 |
__resetButtonState()
|
348 |
__setStartMsg("")
|
|
|
|
|
|
|
349 |
|
350 |
with st.chat_message("user", avatar=C.USER_ICON):
|
351 |
st.markdown(prompt)
|
@@ -391,29 +426,8 @@ if prompt := (
|
|
391 |
if len(responseParts) > 1:
|
392 |
[response, jsonStr] = responseParts
|
393 |
|
394 |
-
imagePath = None
|
395 |
imageContainer = st.empty()
|
396 |
-
|
397 |
-
(imagePrompt, loaderText) = __getImagePromptDetails(prompt, response)
|
398 |
-
if imagePrompt:
|
399 |
-
imgContainer = imageContainer.container()
|
400 |
-
imgContainer.write(
|
401 |
-
f"""
|
402 |
-
<div class='blinking code'>
|
403 |
-
{loaderText}
|
404 |
-
</div>
|
405 |
-
""",
|
406 |
-
unsafe_allow_html=True
|
407 |
-
)
|
408 |
-
# imgContainer.markdown(f"`{loaderText}`")
|
409 |
-
imgContainer.image(C.IMAGE_LOADER)
|
410 |
-
(imagePath, seed) = __generateImage(imagePrompt)
|
411 |
-
imageContainer.image(imagePath)
|
412 |
-
except Exception as e:
|
413 |
-
U.pprint(e)
|
414 |
-
imageContainer.empty()
|
415 |
-
|
416 |
-
__resetSelectedStory()
|
417 |
|
418 |
st.session_state.chatHistory.append({
|
419 |
"role": "assistant",
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit.delta_generator import DeltaGenerator
|
3 |
import os
|
4 |
import time
|
5 |
import json
|
|
|
78 |
U.pprint("lot of consecutive repeating words")
|
79 |
return True
|
80 |
|
81 |
+
if len(re.findall(r'\n\n', response)) > 30:
|
82 |
U.pprint("lots of paragraphs")
|
83 |
return True
|
84 |
|
|
|
285 |
return result
|
286 |
|
287 |
|
288 |
+
def __paintImageIfApplicable(
|
289 |
+
imageContainer: DeltaGenerator,
|
290 |
+
prompt: str,
|
291 |
+
response: str,
|
292 |
+
):
|
293 |
+
imagePath = None
|
294 |
+
try:
|
295 |
+
(imagePrompt, loaderText) = __getImagePromptDetails(prompt, response)
|
296 |
+
if imagePrompt:
|
297 |
+
imgContainer = imageContainer.container()
|
298 |
+
imgContainer.write(
|
299 |
+
f"""
|
300 |
+
<div class='blinking code'>
|
301 |
+
{loaderText}
|
302 |
+
</div>
|
303 |
+
""",
|
304 |
+
unsafe_allow_html=True
|
305 |
+
)
|
306 |
+
imgContainer.image(C.IMAGE_LOADER)
|
307 |
+
(imagePath, seed) = __generateImage(imagePrompt)
|
308 |
+
imageContainer.image(imagePath)
|
309 |
+
except Exception as e:
|
310 |
+
U.pprint(e)
|
311 |
+
imageContainer.empty()
|
312 |
+
|
313 |
+
return imagePath
|
314 |
+
|
315 |
+
|
316 |
def __resetButtonState():
|
317 |
st.session_state.buttonValue = ""
|
318 |
|
|
|
340 |
if "selectedStory" not in st.session_state:
|
341 |
__resetSelectedStory()
|
342 |
|
343 |
+
if "selectedStoryTitle" not in st.session_state:
|
344 |
+
st.session_state.selectedStoryTitle = ""
|
345 |
+
|
346 |
if "isStoryChosen" not in st.session_state:
|
347 |
st.session_state.isStoryChosen = False
|
348 |
|
|
|
373 |
if prompt := (
|
374 |
st.chat_input()
|
375 |
or st.session_state["buttonValue"]
|
376 |
+
or st.session_state["selectedStoryTitle"]
|
377 |
or st.session_state["startMsg"]
|
378 |
):
|
379 |
__resetButtonState()
|
380 |
__setStartMsg("")
|
381 |
+
if st.session_state["selectedStoryTitle"] != prompt:
|
382 |
+
__resetSelectedStory()
|
383 |
+
st.session_state.selectedStoryTitle = ""
|
384 |
|
385 |
with st.chat_message("user", avatar=C.USER_ICON):
|
386 |
st.markdown(prompt)
|
|
|
426 |
if len(responseParts) > 1:
|
427 |
[response, jsonStr] = responseParts
|
428 |
|
|
|
429 |
imageContainer = st.empty()
|
430 |
+
imagePath = __paintImageIfApplicable(imageContainer, prompt, response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
|
432 |
st.session_state.chatHistory.append({
|
433 |
"role": "assistant",
|
constants.py
CHANGED
@@ -59,14 +59,14 @@ Asks users to define the purpose of building a story. It can be one of the follo
|
|
59 |
- Company Origin: To craft a compelling narrative about how a company or organization was founded, its mission, and key milestones for use in marketing materials or investor presentations.
|
60 |
- Product Launch: To develop an engaging narrative around a new product or service, focusing on the problem it solves and its unique value proposition for use in marketing campaigns or sales pitches.
|
61 |
- Customer Success / Testimonials: To showcase how a product or service has positively impacted a customer's life or business, creating a relatable narrative for potential customers.
|
62 |
-
- Team Building: To create a shared narrative that reinforces company values, promotes team cohesion
|
63 |
|
64 |
#### Story Time Frame:
|
65 |
Allows story selection from various life stages (childhood, mid-career, recent experiences).
|
66 |
Or Age-wise (below 8, 8-13, 13-15 and so on).
|
67 |
|
68 |
#### Story Focus:
|
69 |
-
Prompts users to select behaviours or leadership qualities to highlight in the story. Allow users to choose upto 3 qualities.
|
70 |
- Resourcefulness (ability to find creative solutions)
|
71 |
- Sincerity (genuine and honest in intentions and words)
|
72 |
- Decisiveness (ability to make firm and timely decisions)
|
@@ -101,7 +101,7 @@ You then lead users through a structured narrative development via the following
|
|
101 |
- Detailing the resolution / Reaching the final goal
|
102 |
- Reflecting on personal growth or lessons learned (What did you do that changed your life forever?)
|
103 |
|
104 |
-
#### Now,
|
105 |
If the user has any suggestions, incorporate them and then show the story again.
|
106 |
|
107 |
|
@@ -134,24 +134,23 @@ After taking user's preference, you show two versions of the final story and ask
|
|
134 |
Allow them to iterate over different narratives to see what fits best for them.
|
135 |
Repeat this process until they are satisfied with the story.
|
136 |
|
137 |
-
After they're satisfied, move to the next tier.
|
138 |
|
139 |
|
140 |
## Tier 3: Story Polishing
|
141 |
-
|
142 |
-
-
|
143 |
-
-
|
144 |
-
|
145 |
-
#### Creative enhancements:
|
146 |
- Some lines or descriptions for inspiration
|
147 |
-
- Tips for maximising emotional resonance and memorability
|
148 |
|
149 |
-
|
150 |
-
You end it with the final story and seek any suggestions from the user to refine the story further. Give them meaningful suggestions to create a more immersive story.
|
151 |
|
152 |
-
|
153 |
-
|
|
|
154 |
|
|
|
|
|
155 |
"""
|
156 |
|
157 |
USER_ICON = "icons/man.png"
|
|
|
59 |
- Company Origin: To craft a compelling narrative about how a company or organization was founded, its mission, and key milestones for use in marketing materials or investor presentations.
|
60 |
- Product Launch: To develop an engaging narrative around a new product or service, focusing on the problem it solves and its unique value proposition for use in marketing campaigns or sales pitches.
|
61 |
- Customer Success / Testimonials: To showcase how a product or service has positively impacted a customer's life or business, creating a relatable narrative for potential customers.
|
62 |
+
- Team Building: To create a shared narrative that reinforces company values, promotes team cohesion.
|
63 |
|
64 |
#### Story Time Frame:
|
65 |
Allows story selection from various life stages (childhood, mid-career, recent experiences).
|
66 |
Or Age-wise (below 8, 8-13, 13-15 and so on).
|
67 |
|
68 |
#### Story Focus:
|
69 |
+
Prompts users to select behaviours or leadership qualities to highlight in the story. Allow users to choose upto 3 qualities, one by one, by asking questions.
|
70 |
- Resourcefulness (ability to find creative solutions)
|
71 |
- Sincerity (genuine and honest in intentions and words)
|
72 |
- Decisiveness (ability to make firm and timely decisions)
|
|
|
101 |
- Detailing the resolution / Reaching the final goal
|
102 |
- Reflecting on personal growth or lessons learned (What did you do that changed your life forever?)
|
103 |
|
104 |
+
#### Now, using these information, create a compelling story in Story-Spine structure as the default style. Then show this story and ask for confirmation before proceeding to the next tier.
|
105 |
If the user has any suggestions, incorporate them and then show the story again.
|
106 |
|
107 |
|
|
|
134 |
Allow them to iterate over different narratives to see what fits best for them.
|
135 |
Repeat this process until they are satisfied with the story.
|
136 |
|
137 |
+
After they're satisfied, move to the next tier of story polishing.
|
138 |
|
139 |
|
140 |
## Tier 3: Story Polishing
|
141 |
+
#### You suggest the user on refining the narrative further by adding:
|
142 |
+
- Impactful quotes/poems
|
143 |
+
- Similes/comparisons
|
|
|
|
|
144 |
- Some lines or descriptions for inspiration
|
|
|
145 |
|
146 |
+
#### You then suggest tips for maximising emotional resonance and memorability
|
|
|
147 |
|
148 |
+
By guiding users through these three tiers, you aim to help novice storytellers towards narrative skill development.
|
149 |
+
You then create the refined and enhanced story and seek any feedback from the user.
|
150 |
+
Give them meaningful suggestions to create a more immersive story.
|
151 |
|
152 |
+
Once the user confirms, you congratulate them with emojis on completing the story and provide the final final refined, enhanced and engaging story in a beatifully formatted manner.
|
153 |
+
Note that the final story should include twist, turns and events that make it really engaging and enjoyable to read.
|
154 |
"""
|
155 |
|
156 |
USER_ICON = "icons/man.png"
|
pages/popular-stories.py
CHANGED
@@ -53,7 +53,8 @@ with storyPlaceholder.container(border=False, height=500):
|
|
53 |
use_container_width=True
|
54 |
):
|
55 |
U.pprint(f"Selected story: {storyTitle}")
|
56 |
-
st.session_state.
|
|
|
57 |
st.session_state.selectedStory = {
|
58 |
"title": storyTitle,
|
59 |
"text": storyDetails
|
|
|
53 |
use_container_width=True
|
54 |
):
|
55 |
U.pprint(f"Selected story: {storyTitle}")
|
56 |
+
st.session_state.isStoryChosen = True
|
57 |
+
st.session_state.selectedStoryTitle = storyTitle
|
58 |
st.session_state.selectedStory = {
|
59 |
"title": storyTitle,
|
60 |
"text": storyDetails
|
utils.py
CHANGED
@@ -2,11 +2,68 @@ import streamlit as st
|
|
2 |
import datetime as DT
|
3 |
import pytz
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def applyCommonStyles():
|
7 |
st.markdown(
|
8 |
-
"""
|
|
|
|
|
|
|
|
|
9 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
@keyframes blinker {
|
11 |
0% {
|
12 |
opacity: 1;
|
@@ -47,13 +104,3 @@ def applyCommonStyles():
|
|
47 |
""",
|
48 |
unsafe_allow_html=True
|
49 |
)
|
50 |
-
|
51 |
-
|
52 |
-
def __nowInIST() -> DT.datetime:
|
53 |
-
return DT.datetime.now(pytz.timezone("Asia/Kolkata"))
|
54 |
-
|
55 |
-
|
56 |
-
def pprint(log: str):
|
57 |
-
now = __nowInIST()
|
58 |
-
now = now.strftime("%Y-%m-%d %H:%M:%S")
|
59 |
-
print(f"[{now}] [{st.session_state.ipAddress}] {log}")
|
|
|
2 |
import datetime as DT
|
3 |
import pytz
|
4 |
|
5 |
+
FONTS = [
|
6 |
+
# "Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900",
|
7 |
+
# "Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900",
|
8 |
+
# "Raleway:ital,wght@0,100..900;1,100..900",
|
9 |
+
# "Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900",
|
10 |
+
# "Nunito:ital,wght@0,200..1000;1,200..1000",
|
11 |
+
# "Quicksand:[email protected]",
|
12 |
+
# "Montserrat:ital,wght@0,100..900;1,100..900",
|
13 |
+
# "Edu+AU+VIC+WA+NT+Dots:[email protected]",
|
14 |
+
"Whisper",
|
15 |
+
# "Merienda:[email protected]",
|
16 |
+
# "Playwrite+DE+Grund:[email protected]",
|
17 |
+
# "Roboto+Slab:[email protected]",
|
18 |
+
"Open+Sans:ital,wght@0,300..800;1,300..800",
|
19 |
+
"Nunito+Sans:ital,opsz,wght@0,6..12,200..1000;1,6..12,200..1000",
|
20 |
+
"Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700",
|
21 |
+
]
|
22 |
+
|
23 |
+
|
24 |
+
def __nowInIST() -> DT.datetime:
|
25 |
+
return DT.datetime.now(pytz.timezone("Asia/Kolkata"))
|
26 |
+
|
27 |
+
|
28 |
+
def pprint(log: str):
|
29 |
+
now = __nowInIST()
|
30 |
+
now = now.strftime("%Y-%m-%d %H:%M:%S")
|
31 |
+
print(f"[{now}] [{st.session_state.ipAddress}] {log}")
|
32 |
+
|
33 |
+
|
34 |
+
def __getFontsUrl():
|
35 |
+
baseLink = "https://fonts.googleapis.com/css2"
|
36 |
+
params = "&".join([f"family={font}" for font in FONTS])
|
37 |
+
params = f"{params}&display=swap"
|
38 |
+
fontsUrl = f"{baseLink}?{params}"
|
39 |
+
# pprint(f"{fontsUrl=}")
|
40 |
+
return fontsUrl
|
41 |
+
|
42 |
|
43 |
def applyCommonStyles():
|
44 |
st.markdown(
|
45 |
+
f"""
|
46 |
+
<head>
|
47 |
+
<link href="{__getFontsUrl()}" rel="stylesheet">
|
48 |
+
</head>
|
49 |
+
""" """
|
50 |
<style>
|
51 |
+
h1 {
|
52 |
+
font-family: 'Whisper';
|
53 |
+
}
|
54 |
+
|
55 |
+
|
56 |
+
h3, div[data-testid="stMarkdownContainer"], .stChatInput textarea, .stButton p {
|
57 |
+
font-family: 'Ubuntu';
|
58 |
+
# font-weight: 300;
|
59 |
+
}
|
60 |
+
div[data-testid="stMarkdownContainer"] *:not(h1):not(h2):not(h3):not(h4):not(h5):not(h6) {
|
61 |
+
font-size: 0.9rem;
|
62 |
+
}
|
63 |
+
.stButton p {
|
64 |
+
font-size: 0.9rem !important;
|
65 |
+
}
|
66 |
+
|
67 |
@keyframes blinker {
|
68 |
0% {
|
69 |
opacity: 1;
|
|
|
104 |
""",
|
105 |
unsafe_allow_html=True
|
106 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|