Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ def text2story(text):
|
|
| 21 |
{"role": "user", "content": f"write me a story of {text}. Story need to be at least 100 words and less than 200 words"}
|
| 22 |
]
|
| 23 |
# Initialize the pipeline with max_length to ensure sufficient length
|
| 24 |
-
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-1.5B-Instruct", max_length=
|
| 25 |
# Generate the story
|
| 26 |
story = pipe(messages)
|
| 27 |
# Extract the generated text
|
|
@@ -31,8 +31,8 @@ def text2story(text):
|
|
| 31 |
# text2audio
|
| 32 |
def text2audio(story_text):
|
| 33 |
# Initialize the pipeline
|
| 34 |
-
|
| 35 |
-
|
| 36 |
# Generate audio
|
| 37 |
audio_output = pipe(story_text)
|
| 38 |
|
|
@@ -56,11 +56,8 @@ def text2audio(story_text):
|
|
| 56 |
output_file = "story_output.wav"
|
| 57 |
sf.write(output_file, audio_data, sampling_rate)
|
| 58 |
|
| 59 |
-
print(f"Audio saved as {output_file}")
|
| 60 |
-
|
| 61 |
return output_file
|
| 62 |
|
| 63 |
-
|
| 64 |
# Main part
|
| 65 |
st.set_page_config(page_title="Your Image to Audio Story",
|
| 66 |
page_icon="🦜")
|
|
@@ -88,6 +85,5 @@ if uploaded_file is not None:
|
|
| 88 |
audio_data = text2audio(story)
|
| 89 |
st.audio("story_output.wav")
|
| 90 |
|
| 91 |
-
|
| 92 |
# Footer
|
| 93 |
st.write("Powered by Hugging Face Transformers and Streamlit")
|
|
|
|
| 21 |
{"role": "user", "content": f"write me a story of {text}. Story need to be at least 100 words and less than 200 words"}
|
| 22 |
]
|
| 23 |
# Initialize the pipeline with max_length to ensure sufficient length
|
| 24 |
+
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-1.5B-Instruct", max_length=260, min_length=130)
|
| 25 |
# Generate the story
|
| 26 |
story = pipe(messages)
|
| 27 |
# Extract the generated text
|
|
|
|
| 31 |
# text2audio
|
| 32 |
def text2audio(story_text):
|
| 33 |
# Initialize the pipeline
|
| 34 |
+
pipe = pipeline("text-to-speech", model="facebook/mms-tts-eng")
|
| 35 |
+
|
| 36 |
# Generate audio
|
| 37 |
audio_output = pipe(story_text)
|
| 38 |
|
|
|
|
| 56 |
output_file = "story_output.wav"
|
| 57 |
sf.write(output_file, audio_data, sampling_rate)
|
| 58 |
|
|
|
|
|
|
|
| 59 |
return output_file
|
| 60 |
|
|
|
|
| 61 |
# Main part
|
| 62 |
st.set_page_config(page_title="Your Image to Audio Story",
|
| 63 |
page_icon="🦜")
|
|
|
|
| 85 |
audio_data = text2audio(story)
|
| 86 |
st.audio("story_output.wav")
|
| 87 |
|
|
|
|
| 88 |
# Footer
|
| 89 |
st.write("Powered by Hugging Face Transformers and Streamlit")
|