Update app.py
Browse files
app.py
CHANGED
|
@@ -31,11 +31,11 @@ def generate_content(image):
|
|
| 31 |
|
| 32 |
# Create prompt for story
|
| 33 |
prompt = (
|
| 34 |
-
f"Write a funny, interesting children's story that precisely centered on this scene {caption}\nStory:"
|
| 35 |
-
f"mention the exact place, location or venue within {caption}"
|
| 36 |
-
f"
|
|
|
|
| 37 |
)
|
| 38 |
-
|
| 39 |
# Generate raw story
|
| 40 |
raw = storyer(
|
| 41 |
prompt,
|
|
@@ -46,10 +46,10 @@ def generate_content(image):
|
|
| 46 |
return_full_text=False
|
| 47 |
)[0]["generated_text"].strip()
|
| 48 |
|
| 49 |
-
# Define allowed characters to keep (removes symbols like * and ~)
|
| 50 |
-
allowed_chars = string.ascii_letters +
|
| 51 |
|
| 52 |
-
# Clean the raw story by keeping only allowed characters
|
| 53 |
clean_raw = ''.join(c for c in raw if c in allowed_chars)
|
| 54 |
|
| 55 |
# Split into words and trim to 100 words
|
|
|
|
| 31 |
|
| 32 |
# Create prompt for story
|
| 33 |
prompt = (
|
| 34 |
+
f"Write a funny, interesting children's story that is precisely centered on this scene {caption}\nStory:"
|
| 35 |
+
f" mention the exact place, location or venue within {caption}"
|
| 36 |
+
f" in third-person narrative, that describes this scene exactly: {caption} "
|
| 37 |
+
f" Avoid numbers, random letter combinations, and single-letter combinations."
|
| 38 |
)
|
|
|
|
| 39 |
# Generate raw story
|
| 40 |
raw = storyer(
|
| 41 |
prompt,
|
|
|
|
| 46 |
return_full_text=False
|
| 47 |
)[0]["generated_text"].strip()
|
| 48 |
|
| 49 |
+
# Define allowed characters to keep (removes digits and symbols like * and ~)
|
| 50 |
+
allowed_chars = string.ascii_letters + " .,!?\"'-"
|
| 51 |
|
| 52 |
+
# Clean the raw story by keeping only allowed characters (this filters out any digits)
|
| 53 |
clean_raw = ''.join(c for c in raw if c in allowed_chars)
|
| 54 |
|
| 55 |
# Split into words and trim to 100 words
|