Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
+
|
| 4 |
+
st.title("Creative Writing Prompt Generator")
|
| 5 |
+
|
| 6 |
+
def generate_writing_prompt(theme):
|
| 7 |
+
# Enhanced prompt to generate creative writing prompts
|
| 8 |
+
prompt = f"Generate a creative writing prompt based on the theme: {theme}. The prompt should inspire engaging and imaginative writing."
|
| 9 |
+
|
| 10 |
+
# Initialize the LLM with the Google API key from Streamlit secrets
|
| 11 |
+
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 12 |
+
|
| 13 |
+
# Invoke the LLM with the prompt
|
| 14 |
+
response = llm.invoke(prompt)
|
| 15 |
+
prompt_text = response.content # Extract the content from the response
|
| 16 |
+
|
| 17 |
+
return prompt_text
|
| 18 |
+
|
| 19 |
+
with st.form("prompt_form"):
|
| 20 |
+
theme = st.text_area("Enter a theme or topic for your writing prompt")
|
| 21 |
+
|
| 22 |
+
submitted = st.form_submit_button("Generate Prompt")
|
| 23 |
+
|
| 24 |
+
if submitted:
|
| 25 |
+
if theme:
|
| 26 |
+
# Generate writing prompt and display it
|
| 27 |
+
prompt = generate_writing_prompt(theme)
|
| 28 |
+
st.info(prompt)
|
| 29 |
+
else:
|
| 30 |
+
# Display an error if no theme is provided
|
| 31 |
+
st.error("Please enter a theme to generate a writing prompt.")
|