Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
# import part
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline
|
| 4 |
-
|
| 5 |
|
| 6 |
# function part
|
| 7 |
# img2text
|
| 8 |
-
def img2text(
|
| 9 |
-
image_to_text_model = pipeline("image-to-text",
|
| 10 |
-
|
| 11 |
-
text = image_to_text_model(img)[0]["generated_text"]
|
| 12 |
return text
|
| 13 |
|
| 14 |
# text2story
|
|
@@ -29,13 +28,15 @@ def text2audio(story_text):
|
|
| 29 |
st.set_page_config(page_title="Your Image to Audio Story",
|
| 30 |
page_icon="🦜")
|
| 31 |
st.header("Turn Your Image to Audio Story")
|
| 32 |
-
uploaded_file = st.file_uploader("Select an Image..."
|
| 33 |
|
| 34 |
|
| 35 |
if uploaded_file is not None:
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
#Stage 1: Image to Text
|
|
|
|
| 1 |
# import part
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
# function part
|
| 7 |
# img2text
|
| 8 |
+
def img2text(url):
|
| 9 |
+
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 10 |
+
text = image_to_text_model(url)[0]["generated_text"]
|
|
|
|
| 11 |
return text
|
| 12 |
|
| 13 |
# text2story
|
|
|
|
| 28 |
st.set_page_config(page_title="Your Image to Audio Story",
|
| 29 |
page_icon="🦜")
|
| 30 |
st.header("Turn Your Image to Audio Story")
|
| 31 |
+
uploaded_file = st.file_uploader("Select an Image...")#, type=["jpg", "jpeg", "png"])
|
| 32 |
|
| 33 |
|
| 34 |
if uploaded_file is not None:
|
| 35 |
+
print(uploaded_file)
|
| 36 |
+
bytes_data = uploaded_file.getvalue()
|
| 37 |
+
with open(uploaded_file.name, "wb") as file:
|
| 38 |
+
file.write(bytes_data)
|
| 39 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 40 |
|
| 41 |
|
| 42 |
#Stage 1: Image to Text
|