Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,41 @@
|
|
| 1 |
# import part
|
| 2 |
import streamlit as st
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import time
|
| 5 |
from transformers import pipeline
|
| 6 |
|
| 7 |
-
# Load models (once globally)
|
| 8 |
-
img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 9 |
-
story_gen = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 10 |
-
|
| 11 |
# function part
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
|
|
|
| 17 |
def text2story(text):
|
| 18 |
-
|
| 19 |
-
story_text =
|
| 20 |
return story_text
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
st.markdown("**Generated Story:**")
|
| 47 |
-
st.write(story)
|
|
|
|
| 1 |
# import part
|
| 2 |
import streamlit as st
|
|
|
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# function part
|
| 6 |
+
# img2text
|
| 7 |
+
def img2text(url):
|
| 8 |
+
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 9 |
+
text = image_to_text_model(url)[0]["generated_text"]
|
| 10 |
+
return text
|
| 11 |
|
| 12 |
+
# text2story
|
| 13 |
def text2story(text):
|
| 14 |
+
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 15 |
+
story_text = pipe(text)[0]['generated_text']
|
| 16 |
return story_text
|
| 17 |
|
| 18 |
+
# text2audio
|
| 19 |
+
def text2audio(story_text):
|
| 20 |
+
pipe = pipeline("text-to-audio", model="Matthijs/mms-tts-eng")
|
| 21 |
+
audio_data = pipe(story_text)
|
| 22 |
+
return audio_data
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def main():
|
| 26 |
+
st.set_page_config(page_title="Your Image to Audio Story", page_icon="🦜")
|
| 27 |
+
st.header("Turn Your Image to Audio Story")
|
| 28 |
+
uploaded_file = st.file_uploader("Select an Image...")
|
| 29 |
+
|
| 30 |
+
if uploaded_file is not None:
|
| 31 |
+
print(uploaded_file)
|
| 32 |
+
bytes_data = uploaded_file.getvalue()
|
| 33 |
+
with open(uploaded_file.name, "wb") as file:
|
| 34 |
+
file.write(bytes_data)
|
| 35 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
#Stage 1: Image to Text
|
| 39 |
+
st.text('Processing img2text...')
|
| 40 |
+
scenario = img2text(uploaded_file.name)
|
| 41 |
+
st.write(scenario)
|
|
|
|
|
|