smtsead commited on
Commit
3e426ea
Β·
verified Β·
1 Parent(s): abdb243

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
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 DistilGPT2 for faster text generation
23
- story_generator = pipeline("text-generation", model="distilgpt2")
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 fast TTS model from Hugging Face (e.g., Facebook's FastSpeech2)
38
- tts_pipeline = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")
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