File size: 1,561 Bytes
ca48ed6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
import requests
from PIL import Image
from io import BytesIO

# Function to fetch wallpapers
def fetch_wallpapers():
    # You can replace this with your own list of image URLs.
    wallpaper_urls = [
        "https://example.com/wallpaper1.jpg",
        "https://example.com/wallpaper2.jpg",
        "https://example.com/wallpaper3.jpg",
        # Add more URLs
    ]
    return wallpaper_urls

# Function to download the image from URL
def download_image(url):
    response = requests.get(url)
    img = Image.open(BytesIO(response.content))
    return img

# Title of the app
st.title("Wallpaper App")

# Displaying a description
st.write("Browse through a collection of beautiful wallpapers and download them!")

# Fetching wallpapers
wallpapers = fetch_wallpapers()

# Display wallpapers with a download button
for url in wallpapers:
    img = download_image(url)
    
    # Display the image
    st.image(img, caption="Wallpaper", use_column_width=True)
    
    # Download button
    if st.button(f"Download Wallpaper", key=url):
        # Save the image temporarily
        response = requests.get(url)
        with open("temp_wallpaper.jpg", "wb") as f:
            f.write(response.content)
        
        # Let the user download the image
        st.download_button(
            label="Download this wallpaper",
            data=open("temp_wallpaper.jpg", "rb").read(),
            file_name="wallpaper.jpg",
            mime="image/jpeg",
        )

# You can also add categories or search functionality if needed