Update app.py
Browse files
app.py
CHANGED
|
@@ -1,79 +1,38 @@
|
|
| 1 |
-
|
| 2 |
-
# import streamlit as st
|
| 3 |
-
# import time
|
| 4 |
-
|
| 5 |
-
# def main():
|
| 6 |
-
# # Title
|
| 7 |
-
# st.title("Streamlit Functions Demo")
|
| 8 |
-
|
| 9 |
-
# # Write
|
| 10 |
-
# st.write("This demo showcases various Streamlit functions.")
|
| 11 |
-
|
| 12 |
-
# # File Uploader
|
| 13 |
-
# uploaded_file = st.file_uploader("Choose an image file")
|
| 14 |
-
# if uploaded_file is not None:
|
| 15 |
-
# # Display the uploaded image
|
| 16 |
-
# st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 17 |
-
|
| 18 |
-
# # Spinner
|
| 19 |
-
# if st.button("Process Image"):
|
| 20 |
-
# with st.spinner('Processing...'):
|
| 21 |
-
# time.sleep(2) # Simulate a long computation
|
| 22 |
-
# st.success('Processing complete!')
|
| 23 |
-
|
| 24 |
-
# # Audio
|
| 25 |
-
# st.write("Here is an audio sample:")
|
| 26 |
-
# audio_file = open('path/to/your/audio.mp3', 'rb')
|
| 27 |
-
# st.audio(audio_file.read(), format='audio/mp3')
|
| 28 |
-
|
| 29 |
-
# # Button
|
| 30 |
-
# if st.button('Click me'):
|
| 31 |
-
# st.write('Button clicked!')
|
| 32 |
-
|
| 33 |
-
# if __name__ == "__main__":
|
| 34 |
-
# main()
|
| 35 |
-
|
| 36 |
import streamlit as st
|
|
|
|
|
|
|
| 37 |
from transformers import pipeline
|
| 38 |
|
| 39 |
-
# Function
|
| 40 |
def generate_image_caption(image_path):
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
-
# Function to generate story from text
|
| 46 |
def text2story(text):
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
st.title("Image to Story Generator")
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if uploaded_file is not None:
|
| 59 |
-
# Display the uploaded image
|
| 60 |
-
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 61 |
-
|
| 62 |
-
# Generate caption button
|
| 63 |
-
if st.button("Generate Caption"):
|
| 64 |
-
with st.spinner('Generating caption...'):
|
| 65 |
-
caption = generate_image_caption(uploaded_file)
|
| 66 |
-
st.write("Generated Caption:", caption)
|
| 67 |
-
|
| 68 |
-
# Generate story button
|
| 69 |
-
if st.button("Generate Story"):
|
| 70 |
-
with st.spinner('Generating story...'):
|
| 71 |
-
generated_story = text2story(caption)
|
| 72 |
-
st.write("Generated Story:", generated_story)
|
| 73 |
|
| 74 |
-
|
| 75 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
main()
|
| 79 |
|
|
|
|
| 1 |
+
# Import Part
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
+
import time
|
| 4 |
+
from PIL import Imgage
|
| 5 |
from transformers import pipeline
|
| 6 |
|
| 7 |
+
# Function Part
|
| 8 |
def generate_image_caption(image_path):
|
| 9 |
+
img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
|
| 10 |
+
result = img2caption(image_path)
|
| 11 |
+
return result[0]['generated_text']
|
| 12 |
|
|
|
|
| 13 |
def text2story(text):
|
| 14 |
+
text2story = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 15 |
+
generated_story = text2story(text)
|
| 16 |
+
return generated_story[0]['generated_text']
|
| 17 |
+
|
| 18 |
+
# Main Part
|
| 19 |
+
|
| 20 |
+
# App title
|
| 21 |
+
st.title("Assignment")
|
| 22 |
|
| 23 |
+
# Write some text
|
| 24 |
+
st.write("Welcome to a demo app showcasting basic streamlit component")
|
|
|
|
| 25 |
|
| 26 |
+
# file upload
|
| 27 |
+
uploaded_image = st.file_uploader("Upload an image", type=['jpg','jpeg','png'])
|
| 28 |
+
# uploaded_model = st.file_uploader("Upload an audio file", type = ['mp3','mov','egg'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
if uploaded_image is not None:
|
| 31 |
+
with st.spinner("Leading image..."):
|
| 32 |
+
time.sleep(1) # Simulate a delay
|
| 33 |
+
image = image.open(uploaded_image)
|
| 34 |
+
caption = generate_image_caption(image)
|
| 35 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 36 |
|
| 37 |
+
#Play audio with apinner:
|
|
|
|
| 38 |
|