| |
| import streamlit as st |
| import time |
| from PIL import Image |
| from transformers import pipeline |
|
|
| |
| def generate_image_caption(image_path): |
| img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large") |
| result = img2caption(image_path) |
| return result[0]['generated_text'] |
|
|
| def text2story(text): |
| text2story = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2") |
| generated_story = text2story(text) |
| return generated_story[0]['generated_text'] |
|
|
| |
|
|
| |
| st.title("Assignment") |
|
|
| |
| st.write("Welcome to a demo app showcasting basic streamlit component") |
|
|
| |
| uploaded_image = st.file_uploader("Upload an image", type=['jpg','jpeg','png']) |
| uploaded_audio = st.file_uploader("Upload an audio file", type = ['mp3','mov','egg']) |
|
|
| if uploaded_image is not None: |
| with st.spinner("Loading image..."): |
| time.sleep(1) |
| image = Image.open(uploaded_image) |
| caption = generate_image_caption(image) |
| print(caption) |
| st.image(image, caption='Uploaded Image', use_column_width=True) |
|
|
| |
| if uploaded_audio is not None: |
| with st.spinner("Loading audio..."): |
| time.sleep(1) |
| st.audo(uploaded_audio) |
|
|
| |
| if st.button("Click Me"): |
| st.write("you clicked the button!") |
|
|
|
|