File size: 2,979 Bytes
6ea1084
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import streamlit as st
from zipfile import ZipFile
import os
import pandas as pd

# Helper functions for image and video captioning (to be implemented)
def caption_images(image_folder):
    # Dummy implementation, replace with actual model inference
    captions = {"image1.jpg": "A beautiful scenery", "image2.jpg": "A cute puppy"}
    return captions

def caption_video(video_file):
    # Dummy implementation, replace with actual model inference
    return "A summary of the video content."

# Main App
st.title("Multimedia Captioning and Search App")

# Sidebar options
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")

# Handling image zip file upload
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")
    # Save captions to CSV
    df_images = pd.DataFrame(list(image_captions.items()), columns=["Image", "Caption"])
    df_images.to_csv("image_captions.csv", index=False)

# Handling video file upload
if uploaded_video is not None:
    video_caption = caption_video(uploaded_video)
    # Save caption to CSV
    df_video = pd.DataFrame([["video_frame.jpg", video_caption]], columns=["Video Frame", "Caption"])
    df_video.to_csv("video_captions.csv", index=False)
    # Extract and display one frame from video (dummy implementation)
    st.image("video_frame.jpg", caption=video_caption)

# Display gallery of images and videos with captions
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"])

# Search functionality
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"])