|
|
import streamlit as st |
|
|
from zipfile import ZipFile |
|
|
import os |
|
|
import pandas as pd |
|
|
|
|
|
|
|
|
def caption_images(image_folder): |
|
|
|
|
|
captions = {"image1.jpg": "A beautiful scenery", "image2.jpg": "A cute puppy"} |
|
|
return captions |
|
|
|
|
|
def caption_video(video_file): |
|
|
|
|
|
return "A summary of the video content." |
|
|
|
|
|
|
|
|
st.title("Multimedia Captioning and Search App") |
|
|
|
|
|
|
|
|
st.sidebar.header("Options") |
|
|
st.sidebar.subheader("Upload Files") |
|
|
uploaded_zip = st.sidebar.file_uploader("Upload a ZIP file of images", type="zip") |
|
|
uploaded_video = st.sidebar.file_uploader("Upload a video file", type=["mp4", "avi", "mov"]) |
|
|
|
|
|
st.sidebar.subheader("Search") |
|
|
search_input = st.sidebar.text_input("Enter search term") |
|
|
|
|
|
|
|
|
if uploaded_zip is not None: |
|
|
with ZipFile(uploaded_zip, 'r') as zip_ref: |
|
|
zip_ref.extractall("uploaded_images") |
|
|
st.write("Images extracted successfully!") |
|
|
image_captions = caption_images("uploaded_images") |
|
|
|
|
|
df_images = pd.DataFrame(list(image_captions.items()), columns=["Image", "Caption"]) |
|
|
df_images.to_csv("image_captions.csv", index=False) |
|
|
|
|
|
|
|
|
if uploaded_video is not None: |
|
|
video_caption = caption_video(uploaded_video) |
|
|
|
|
|
df_video = pd.DataFrame([["video_frame.jpg", video_caption]], columns=["Video Frame", "Caption"]) |
|
|
df_video.to_csv("video_captions.csv", index=False) |
|
|
|
|
|
st.image("video_frame.jpg", caption=video_caption) |
|
|
|
|
|
|
|
|
st.subheader("Gallery") |
|
|
if os.path.exists("image_captions.csv"): |
|
|
df_images = pd.read_csv("image_captions.csv") |
|
|
for index, row in df_images.iterrows(): |
|
|
st.image(f"uploaded_images/{row['Image']}", caption=row["Caption"]) |
|
|
|
|
|
if os.path.exists("video_captions.csv"): |
|
|
df_video = pd.read_csv("video_captions.csv") |
|
|
for index, row in df_video.iterrows(): |
|
|
st.image(row["Video Frame"], caption=row["Caption"]) |
|
|
|
|
|
|
|
|
if search_input: |
|
|
st.subheader("Search Results") |
|
|
if os.path.exists("image_captions.csv"): |
|
|
df_images = pd.read_csv("image_captions.csv") |
|
|
search_results = df_images[df_images["Caption"].str.contains(search_input, case=False, na=False)] |
|
|
for index, row in search_results.iterrows(): |
|
|
st.image(f"uploaded_images/{row['Image']}", caption=row["Caption"]) |
|
|
|
|
|
if os.path.exists("video_captions.csv"): |
|
|
df_video = pd.read_csv("video_captions.csv") |
|
|
search_results = df_video[df_video["Caption"].str.contains(search_input, case=False, na=False)] |
|
|
for index, row in search_results.iterrows(): |
|
|
st.image(row["Video Frame"], caption=row["Caption"]) |
|
|
|