awacke1's picture
Update app.py
f8ac18d verified
raw
history blame contribute delete
No virus
2.29 kB
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()