Szeyu commited on
Commit
6b63858
·
verified ·
1 Parent(s): c78ad3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -19,6 +19,13 @@ def load_pipelines():
19
 
20
  captioner, storyer, tts = load_pipelines()
21
 
 
 
 
 
 
 
 
22
  # Function part
23
  # Function to generate content from an image
24
  def generate_content(image):
@@ -29,11 +36,18 @@ def generate_content(image):
29
  st.write("**🌟 What's in the picture: 🌟**")
30
  st.write(caption)
31
 
32
- # Create prompt for story
 
 
 
 
33
  prompt = (
34
  f"Write a funny, warm children's story for ages 3-10, 50–100 words, "
35
- f"in third-person narrative, that describes this scene exactly: {caption} "
36
- f"mention the exact place, location or venue within {caption}"
 
 
 
37
  )
38
 
39
  # Generate raw story
 
19
 
20
  captioner, storyer, tts = load_pipelines()
21
 
22
+ # Function to extract keywords from caption
23
+ def extract_keywords(caption):
24
+ stop_words = {'the', 'a', 'an', 'in', 'on', 'at', 'of', 'to', 'is', 'are', 'with', 'and'}
25
+ words = caption.lower().split()
26
+ keywords = [word.strip(".,!?\"'") for word in words if word not in stop_words and len(word) > 2]
27
+ return keywords
28
+
29
  # Function part
30
  # Function to generate content from an image
31
  def generate_content(image):
 
36
  st.write("**🌟 What's in the picture: 🌟**")
37
  st.write(caption)
38
 
39
+ # Extract keywords from the caption
40
+ keywords = extract_keywords(caption)
41
+ keywords_str = ", ".join(keywords)
42
+
43
+ # Create prompt for story with narrative structure
44
  prompt = (
45
  f"Write a funny, warm children's story for ages 3-10, 50–100 words, "
46
+ f"in third-person narrative. The story must describe this scene exactly: {caption}. "
47
+ f"Include these keywords from the caption: {keywords_str}. "
48
+ f"Feature a named protagonist (a child), a simple problem or goal, and a happy resolution. "
49
+ f"Mention the exact place, location, or venue from the scene (e.g., park, pool, gym). "
50
+ f"Keep the tone playful and engaging."
51
  )
52
 
53
  # Generate raw story