Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from zipfile import ZipFile
|
| 3 |
+
import os
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
# Helper functions for image and video captioning (to be implemented)
|
| 7 |
+
def caption_images(image_folder):
|
| 8 |
+
# Dummy implementation, replace with actual model inference
|
| 9 |
+
captions = {"image1.jpg": "A beautiful scenery", "image2.jpg": "A cute puppy"}
|
| 10 |
+
return captions
|
| 11 |
+
|
| 12 |
+
def caption_video(video_file):
|
| 13 |
+
# Dummy implementation, replace with actual model inference
|
| 14 |
+
return "A summary of the video content."
|
| 15 |
+
|
| 16 |
+
# Main App
|
| 17 |
+
st.title("Multimedia Captioning and Search App")
|
| 18 |
+
|
| 19 |
+
# Sidebar options
|
| 20 |
+
st.sidebar.header("Options")
|
| 21 |
+
st.sidebar.subheader("Upload Files")
|
| 22 |
+
uploaded_zip = st.sidebar.file_uploader("Upload a ZIP file of images", type="zip")
|
| 23 |
+
uploaded_video = st.sidebar.file_uploader("Upload a video file", type=["mp4", "avi", "mov"])
|
| 24 |
+
|
| 25 |
+
st.sidebar.subheader("Search")
|
| 26 |
+
search_input = st.sidebar.text_input("Enter search term")
|
| 27 |
+
|
| 28 |
+
# Handling image zip file upload
|
| 29 |
+
if uploaded_zip is not None:
|
| 30 |
+
with ZipFile(uploaded_zip, 'r') as zip_ref:
|
| 31 |
+
zip_ref.extractall("uploaded_images")
|
| 32 |
+
st.write("Images extracted successfully!")
|
| 33 |
+
image_captions = caption_images("uploaded_images")
|
| 34 |
+
# Save captions to CSV
|
| 35 |
+
df_images = pd.DataFrame(list(image_captions.items()), columns=["Image", "Caption"])
|
| 36 |
+
df_images.to_csv("image_captions.csv", index=False)
|
| 37 |
+
|
| 38 |
+
# Handling video file upload
|
| 39 |
+
if uploaded_video is not None:
|
| 40 |
+
video_caption = caption_video(uploaded_video)
|
| 41 |
+
# Save caption to CSV
|
| 42 |
+
df_video = pd.DataFrame([["video_frame.jpg", video_caption]], columns=["Video Frame", "Caption"])
|
| 43 |
+
df_video.to_csv("video_captions.csv", index=False)
|
| 44 |
+
# Extract and display one frame from video (dummy implementation)
|
| 45 |
+
st.image("video_frame.jpg", caption=video_caption)
|
| 46 |
+
|
| 47 |
+
# Display gallery of images and videos with captions
|
| 48 |
+
st.subheader("Gallery")
|
| 49 |
+
if os.path.exists("image_captions.csv"):
|
| 50 |
+
df_images = pd.read_csv("image_captions.csv")
|
| 51 |
+
for index, row in df_images.iterrows():
|
| 52 |
+
st.image(f"uploaded_images/{row['Image']}", caption=row["Caption"])
|
| 53 |
+
|
| 54 |
+
if os.path.exists("video_captions.csv"):
|
| 55 |
+
df_video = pd.read_csv("video_captions.csv")
|
| 56 |
+
for index, row in df_video.iterrows():
|
| 57 |
+
st.image(row["Video Frame"], caption=row["Caption"])
|
| 58 |
+
|
| 59 |
+
# Search functionality
|
| 60 |
+
if search_input:
|
| 61 |
+
st.subheader("Search Results")
|
| 62 |
+
if os.path.exists("image_captions.csv"):
|
| 63 |
+
df_images = pd.read_csv("image_captions.csv")
|
| 64 |
+
search_results = df_images[df_images["Caption"].str.contains(search_input, case=False, na=False)]
|
| 65 |
+
for index, row in search_results.iterrows():
|
| 66 |
+
st.image(f"uploaded_images/{row['Image']}", caption=row["Caption"])
|
| 67 |
+
|
| 68 |
+
if os.path.exists("video_captions.csv"):
|
| 69 |
+
df_video = pd.read_csv("video_captions.csv")
|
| 70 |
+
search_results = df_video[df_video["Caption"].str.contains(search_input, case=False, na=False)]
|
| 71 |
+
for index, row in search_results.iterrows():
|
| 72 |
+
st.image(row["Video Frame"], caption=row["Caption"])
|