Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,9 +11,8 @@ def img2text(url):
|
|
| 11 |
|
| 12 |
# text2story
|
| 13 |
def text2story(text):
|
| 14 |
-
messages = [{"role": "user", "content": text}]
|
| 15 |
text_generation_model = pipeline("text-generation", model="microsoft/Phi-4-mini-instruct", trust_remote_code=True)
|
| 16 |
-
story_text = text_generation_model(
|
| 17 |
return story_text
|
| 18 |
|
| 19 |
# text2audio
|
|
@@ -21,8 +20,8 @@ def text2audio(story_text):
|
|
| 21 |
text_to_speech_model = pipeline("text-to-speech", model="suno/bark-small")
|
| 22 |
audio_data = text_to_speech_model(story_text)
|
| 23 |
return {
|
| 24 |
-
'audio': audio_data[
|
| 25 |
-
'sampling_rate': audio_data[
|
| 26 |
}
|
| 27 |
|
| 28 |
#main part
|
|
@@ -41,24 +40,23 @@ if uploaded_file is not None:
|
|
| 41 |
st.image(uploaded_file, caption="Uploaded Image",
|
| 42 |
use_column_width=True)
|
| 43 |
|
| 44 |
-
#Stage 1: Image to Text
|
| 45 |
st.text('Processing img2text...')
|
| 46 |
scenario = img2text(uploaded_file.name)
|
| 47 |
st.write(scenario)
|
| 48 |
|
| 49 |
-
#Stage 2: Text to Story
|
| 50 |
st.text('Generating a story...')
|
| 51 |
story = text2story(scenario)
|
| 52 |
st.write(story)
|
| 53 |
|
| 54 |
-
#Stage 3: Story to Audio data
|
| 55 |
st.text('Generating audio data...')
|
| 56 |
-
audio_data =text2audio(story)
|
| 57 |
|
| 58 |
# Play button
|
| 59 |
if st.button("Play Audio"):
|
| 60 |
st.audio(audio_data['audio'],
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
st.audio("kids_playing_audio.wav")
|
|
|
|
| 11 |
|
| 12 |
# text2story
|
| 13 |
def text2story(text):
|
|
|
|
| 14 |
text_generation_model = pipeline("text-generation", model="microsoft/Phi-4-mini-instruct", trust_remote_code=True)
|
| 15 |
+
story_text = text_generation_model(text)[0]["generated_text"]
|
| 16 |
return story_text
|
| 17 |
|
| 18 |
# text2audio
|
|
|
|
| 20 |
text_to_speech_model = pipeline("text-to-speech", model="suno/bark-small")
|
| 21 |
audio_data = text_to_speech_model(story_text)
|
| 22 |
return {
|
| 23 |
+
'audio': audio_data["audio"],
|
| 24 |
+
'sampling_rate': audio_data["sampling_rate"]
|
| 25 |
}
|
| 26 |
|
| 27 |
#main part
|
|
|
|
| 40 |
st.image(uploaded_file, caption="Uploaded Image",
|
| 41 |
use_column_width=True)
|
| 42 |
|
| 43 |
+
# Stage 1: Image to Text
|
| 44 |
st.text('Processing img2text...')
|
| 45 |
scenario = img2text(uploaded_file.name)
|
| 46 |
st.write(scenario)
|
| 47 |
|
| 48 |
+
# Stage 2: Text to Story
|
| 49 |
st.text('Generating a story...')
|
| 50 |
story = text2story(scenario)
|
| 51 |
st.write(story)
|
| 52 |
|
| 53 |
+
# Stage 3: Story to Audio data
|
| 54 |
st.text('Generating audio data...')
|
| 55 |
+
audio_data = text2audio(story)
|
| 56 |
|
| 57 |
# Play button
|
| 58 |
if st.button("Play Audio"):
|
| 59 |
st.audio(audio_data['audio'],
|
| 60 |
+
format="audio/wav",
|
| 61 |
+
start_time=0,
|
| 62 |
+
sample_rate=audio_data['sampling_rate'])
|
|
|