Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,79 @@
|
|
| 1 |
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import time
|
| 4 |
|
| 5 |
-
def main():
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 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 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
st.write('Button clicked!')
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
-
|
|
|
|
|
|
| 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 to generate image caption
|
| 40 |
+
def generate_image_caption(image_path):
|
| 41 |
+
img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
|
| 42 |
+
result = img2caption(image_path)
|
| 43 |
+
return result[0]['generated_text']
|
| 44 |
+
|
| 45 |
+
# Function to generate story from text
|
| 46 |
+
def text2story(text):
|
| 47 |
+
text2story = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 48 |
+
generated_story = text2story(text)
|
| 49 |
+
return generated_story[0]['generated_text']
|
| 50 |
|
| 51 |
+
# Main function for the Streamlit app
|
| 52 |
+
def main():
|
| 53 |
+
st.title("Image to Story Generator")
|
| 54 |
+
|
| 55 |
+
# File uploader for image
|
| 56 |
+
uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
|
| 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 |
+
# Audio generation placeholder (to be implemented)
|
| 75 |
+
st.write("Audio generation feature coming soon...")
|
|
|
|
| 76 |
|
| 77 |
if __name__ == "__main__":
|
| 78 |
+
main()
|
| 79 |
+
|