Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ def img2text(url):
|
|
9 |
try:
|
10 |
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
11 |
text = image_to_text_model(url)[0]["generated_text"]
|
|
|
|
|
12 |
# Make the caption more fun and happy
|
13 |
fun_caption = f"π Wow! This picture shows {text.lower()}. Letβs turn it into a fun story! π"
|
14 |
return fun_caption
|
@@ -19,11 +21,13 @@ def img2text(url):
|
|
19 |
# text2story
|
20 |
def text2story(text):
|
21 |
try:
|
22 |
-
# Use
|
23 |
-
story_generator = pipeline("text-generation", model="
|
24 |
# Add a fun and happy prompt to guide the story generation
|
25 |
prompt = f"One sunny day, {text}. "
|
26 |
story = story_generator(prompt, max_length=100, num_return_sequences=1)[0]["generated_text"]
|
|
|
|
|
27 |
# Make the story more fun by adding a happy ending
|
28 |
happy_story = story + " And everyone had a big smile on their faces at the end of the day! ππ"
|
29 |
return happy_story
|
@@ -34,8 +38,8 @@ def text2story(text):
|
|
34 |
# text2audio
|
35 |
def text2audio(story_text):
|
36 |
try:
|
37 |
-
# Use a
|
38 |
-
tts_pipeline = pipeline("text-to-speech", model="
|
39 |
audio_output = tts_pipeline(story_text)
|
40 |
audio_file = "story_audio.wav"
|
41 |
# Save the audio file
|
|
|
9 |
try:
|
10 |
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
11 |
text = image_to_text_model(url)[0]["generated_text"]
|
12 |
+
# Remove unwanted words like "illustration"
|
13 |
+
text = text.replace("illustration", "").strip()
|
14 |
# Make the caption more fun and happy
|
15 |
fun_caption = f"π Wow! This picture shows {text.lower()}. Letβs turn it into a fun story! π"
|
16 |
return fun_caption
|
|
|
21 |
# text2story
|
22 |
def text2story(text):
|
23 |
try:
|
24 |
+
# Use a better model for text generation (e.g., GPT-Neo)
|
25 |
+
story_generator = pipeline("text-generation", model="EleutherAI/gpt-neo-125M")
|
26 |
# Add a fun and happy prompt to guide the story generation
|
27 |
prompt = f"One sunny day, {text}. "
|
28 |
story = story_generator(prompt, max_length=100, num_return_sequences=1)[0]["generated_text"]
|
29 |
+
# Remove any unwanted text (e.g., usernames, special characters)
|
30 |
+
story = " ".join([word for word in story.split() if not word.startswith("@") and not word.startswith("http")])
|
31 |
# Make the story more fun by adding a happy ending
|
32 |
happy_story = story + " And everyone had a big smile on their faces at the end of the day! ππ"
|
33 |
return happy_story
|
|
|
38 |
# text2audio
|
39 |
def text2audio(story_text):
|
40 |
try:
|
41 |
+
# Use a reliable TTS model (e.g., ESPnet's VITS model)
|
42 |
+
tts_pipeline = pipeline("text-to-speech", model="espnet/kan-bayashi_ljspeech_vits")
|
43 |
audio_output = tts_pipeline(story_text)
|
44 |
audio_file = "story_audio.wav"
|
45 |
# Save the audio file
|