File size: 1,201 Bytes
d273843 |
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 |
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.")
|