import streamlit as st from langchain_google_genai import ChatGoogleGenerativeAI st.title("Creative Writing Prompt Generator") def generate_writing_prompt(theme): # Enhanced prompt to generate creative writing prompts prompt = f"Generate a creative writing prompt based on the theme: {theme}. The prompt should inspire engaging and imaginative writing." # Initialize the LLM with the Google API key from Streamlit secrets llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"]) # Invoke the LLM with the prompt response = llm.invoke(prompt) prompt_text = response.content # Extract the content from the response return prompt_text with st.form("prompt_form"): theme = st.text_area("Enter a theme or topic for your writing prompt") submitted = st.form_submit_button("Generate Prompt") if submitted: if theme: # Generate writing prompt and display it prompt = generate_writing_prompt(theme) st.info(prompt) else: # Display an error if no theme is provided st.error("Please enter a theme to generate a writing prompt.")