import streamlit as st from langchain_groq import ChatGroq from langchain.schema import AIMessage, HumanMessage, SystemMessage # Initialize ChatGroq with the API key directly in the code llm = ChatGroq( api_key="YourAPIKEY", temperature=0.7, max_retries=2, ) def get_ai_response(prompt): messages = [ SystemMessage(content="You are a helpful AI assistant specializing in storytelling."), HumanMessage(content=prompt) ] response = llm.invoke(messages) return response.content def main(): st.title("AI-Powered Storytelling Assistant") # Tier selection tier = st.sidebar.radio("Select Tier", ["Tier 1: Story Creation", "Tier 2: Story Enhancement", "Tier 3: Story Polishing"]) if tier == "Tier 1: Story Creation": tier_1_story_creation() elif tier == "Tier 2: Story Enhancement": tier_2_story_enhancement() elif tier == "Tier 3: Story Polishing": tier_3_story_polishing() def tier_1_story_creation(): st.header("Story Origin") origin = st.radio("Select your story origin:", ["Personal Anecdote", "Fictional"]) # Story Use Case st.header("Story Use Case") use_case = st.selectbox("What's the purpose of your story?", ["Profile Story", "Social Media Content", "Other"]) # Story Time Frame st.header("Story Time Frame") time_frame = st.selectbox("Select the time frame of your story:", ["Childhood", "Mid-career", "Recent Experience"]) # Age Selection age_range = st.selectbox("Select your age range:", ["Below 8", "8-13", "13-15", "16-18", "19-25", "26-35", "36-50", "51+"]) # Story Focus st.header("Story Focus") leadership_traits = ["Generosity", "Integrity", "Loyalty", "Devotion", "Kindness", "Sincerity", "Self-control", "Confidence", "Persuasiveness", "Ambition", "Resourcefulness", "Decisiveness", "Faithfulness", "Patience", "Determination", "Persistence", "Fairness", "Cooperation", "Optimism", "Proactive", "Charisma", "Ethics", "Relentlessness", "Authority", "Enthusiasm", "Boldness"] focus = st.multiselect("Select behaviours or leadership qualities to highlight:", leadership_traits) # Story Type st.header("Story Type") story_types = [ "Where we came from: A founding Story", "Why we can't stay here: A case-for-change story", "Where we're going: A vision story", "How we're going to get there: A strategy story", "Why I lead the way I do: Leadership philosophy story", "Why you should want to work here: A rallying story", "Personal stories: Who you are, what you do, how you do it, and who you do it for", "What we believe: A story about values", "Who we serve: A customer story", "What we do for our customers: A sales story", "How we're different: A marketing story" ] story_type = st.selectbox("Select the type of story you want to tell:", story_types) # Guided Storytelling Framework st.header("Guided Storytelling") day_description = st.text_area("Describe the day it happened:") call_to_action = st.text_input("What was the Call to Action / Invitation?") obstacles = st.text_area("Describe up to three obstacles (4 lines each):") emotions = st.text_area("Explore emotions/fears experienced during the incident:") helpers = st.text_input("Recognize the helpers / any objects of help in the incident:") resolution = st.text_area("Detail the resolution / Reaching the final goal:") lessons = st.text_area("Reflect on personal growth or lessons learned:") if st.button("Generate Story"): # Combine all inputs into a prompt for the AI prompt = f"""Create a story based on the following inputs: Origin: {origin} Use Case: {use_case} Time Frame: {time_frame} Age Range: {age_range} Focus: {', '.join(focus)} Story Type: {story_type} Day Description: {day_description} Call to Action: {call_to_action} Obstacles: {obstacles} Emotions: {emotions} Helpers: {helpers} Resolution: {resolution} Lessons Learned: {lessons} Please craft a compelling narrative incorporating all these elements.""" # Get AI response story = get_ai_response(prompt) # Display the generated story st.subheader("Your Generated Story:") st.write(story) def tier_2_story_enhancement(): st.header("Tier 2: Story Enhancement") # Load the story from Tier 1 or allow user to input story = st.text_area("Enter your story from Tier 1 or paste it here:", height=300) narrative_structures = [ "The Story Hanger", "The Story Spine", "Hero's Journey", "Beginning to End", "In Media Res (Start the story in the middle)", "Nested Loops", "The Cliffhanger" ] selected_structure = st.selectbox("Select a narrative structure:", narrative_structures) if st.button("Enhance Story"): prompt = f"""Enhance the following story using the {selected_structure} narrative structure: {story} Please restructure the story to fit the chosen narrative structure while maintaining its core elements and message.""" enhanced_story = get_ai_response(prompt) st.subheader("Enhanced Story:") st.write(enhanced_story) def tier_3_story_polishing(): st.header("Tier 3: Story Polishing") # Load the story from Tier 2 or allow user to input story = st.text_area("Enter your enhanced story from Tier 2 or paste it here:", height=300) polish_options = st.multiselect("Select polishing options:", ["Add impactful quotes", "Add similes/comparisons", "Enhance descriptions", "Maximize emotional resonance"]) if st.button("Polish Story"): prompt = f"""Polish the following story by applying these enhancements: {', '.join(polish_options)} {story} Please refine the narrative further by incorporating the selected polishing options. Aim to make the story more impactful, memorable, and emotionally resonant.""" polished_story = get_ai_response(prompt) st.subheader("Polished Story:") st.write(polished_story) # Provide additional tips st.subheader("Tips for maximizing impact:") tips = get_ai_response("Provide 3-5 concise tips for maximizing the emotional resonance and memorability of a story.") st.write(tips) if __name__ == "__main__": main()