File size: 2,287 Bytes
e03a0f4
 
 
 
f8ac18d
e03a0f4
13a4c90
e03a0f4
 
 
 
13a4c90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e03a0f4
13a4c90
e03a0f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13a4c90
 
 
e03a0f4
13a4c90
 
 
 
 
 
e03a0f4
 
 
 
 
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
import streamlit as st
import os
import glob
import zipfile
from urllib.parse import quote

def extract_zip(zip_path, extract_to="extracted_images"):
    with zipfile.ZipFile(zip_path, 'r') as zip_ref:
        zip_ref.extractall(extract_to)
    return extract_to

search_urls = {
    "📖": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
    "🔍": lambda k: f"https://www.google.com/search?q={quote(k)}",
    "▶️": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}",
    "🔎": lambda k: f"https://www.bing.com/search?q={quote(k)}",
    "🎲": lambda k: f"https://huggingface.co/spaces/awacke1/AI-ChatGPT-CPT-Body-Map-Cost?q={quote(k)}",
}

def generate_search_links(filename):
    # Remove the file extension and replace underscores with spaces for search terms
    search_term = filename.rsplit('.', 1)[0].replace("_", " ")
    # Generate markdown links for each search URL
    links_md = ' '.join([f"[{emoji}]({url(search_term)})" for emoji, url in search_urls.items()])
    # Display the markdown with Streamlit
    st.markdown(f"Explore **{search_term}** in: {links_md}", unsafe_allow_html=True)


def main():
    st.title('Zip File Image Gallery')

    # Check for zip files in the current directory
    zip_files = glob.glob('*.zip')
    if zip_files:
        zip_file = zip_files[0]
        st.write(f"Found zip file: {zip_file}")
        file_size = os.path.getsize(zip_file)
        st.write(f"Size: {file_size / (1024 * 1024):.2f} MB")

        # Extract the zip file
        if st.button('Extract Zip File'):
            extract_path = extract_zip(zip_file)
            st.success(f'Extracted to {extract_path}')

            # Display video gallery
            #videos = glob.glob(f'{extract_path}/*.mp4')
            #for video in videos:
            #    st.video(video, format="video/mp4", start_time=0)

            # Display image gallery
            images = glob.glob(f'{extract_path}/*.png')  # Adjusted to include all image file types
            for image in images:
                st.image(image, caption=os.path.basename(image), width=300)
                generate_search_links(os.path.basename(image))
                
    else:
        st.write("No zip files found in the directory.")

if __name__ == "__main__":
    main()