|
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): |
|
|
|
search_term = filename.rsplit('.', 1)[0].replace("_", " ") |
|
|
|
links_md = ' '.join([f"[{emoji}]({url(search_term)})" for emoji, url in search_urls.items()]) |
|
|
|
st.markdown(f"Explore **{search_term}** in: {links_md}", unsafe_allow_html=True) |
|
|
|
|
|
def main(): |
|
st.title('Zip File Image Gallery') |
|
|
|
|
|
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") |
|
|
|
|
|
if st.button('Extract Zip File'): |
|
extract_path = extract_zip(zip_file) |
|
st.success(f'Extracted to {extract_path}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
images = glob.glob(f'{extract_path}/*.png') |
|
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() |
|
|