Spaces:
Running
Running
Upload 2 files
Browse files- app.py +45 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
def img2text(url):
|
5 |
+
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
6 |
+
text = image_to_text_model(url)[0]["generated_text"]
|
7 |
+
return text
|
8 |
+
|
9 |
+
def text2story(text):
|
10 |
+
story_text = pipeline("text-generation", model="meta-llama/Meta-Llama-3-8B")
|
11 |
+
story_text = pipeline("Create a story of maximum 100 words based upon {text}")
|
12 |
+
return story_text
|
13 |
+
|
14 |
+
def text2audio(story_text):
|
15 |
+
audio_data = pipeline("text-to-speech", model="ElvisTsang/facebook-mms-tts-eng")
|
16 |
+
return audio_data
|
17 |
+
|
18 |
+
st.set_page_config(page_title="Once Upon A Time - Storytelling Application", page_icon="📖🏰🦄🧙")
|
19 |
+
st.header("Create a story of yours with an image!")
|
20 |
+
uploaded_file = st.file_uploader("Upload an image of your story!")
|
21 |
+
|
22 |
+
if uploaded_file is not None:
|
23 |
+
print(uploaded_file)
|
24 |
+
bytes_data = uploaded_file.getvalue()
|
25 |
+
with open(uploaded_file.name, "wb") as file:
|
26 |
+
file.write(bytes_data)
|
27 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
28 |
+
|
29 |
+
st.text('Processing img2text...')
|
30 |
+
scenario = img2text(uploaded_file.name)
|
31 |
+
st.write(scenario)
|
32 |
+
|
33 |
+
st.text('Generating a story...')
|
34 |
+
story = text2story(scenario)
|
35 |
+
st.write(story)
|
36 |
+
|
37 |
+
st.text('Generating audio data...')
|
38 |
+
audio_data =text2audio(story)
|
39 |
+
|
40 |
+
if st.button("Story Time!"):
|
41 |
+
st.audio(audio_data['audio'],
|
42 |
+
format="audio/wav",
|
43 |
+
start_time=0,
|
44 |
+
sample_rate = audio_data['sampling_rate'])
|
45 |
+
st.audio(audio_data)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
torchaudio
|