|
|
import streamlit as st |
|
|
import os |
|
|
import requests |
|
|
from PIL import Image |
|
|
from io import BytesIO |
|
|
|
|
|
|
|
|
def fetch_wallpapers(): |
|
|
|
|
|
wallpaper_urls = [ |
|
|
"https://example.com/wallpaper1.jpg", |
|
|
"https://example.com/wallpaper2.jpg", |
|
|
"https://example.com/wallpaper3.jpg", |
|
|
|
|
|
] |
|
|
return wallpaper_urls |
|
|
|
|
|
|
|
|
def download_image(url): |
|
|
response = requests.get(url) |
|
|
img = Image.open(BytesIO(response.content)) |
|
|
return img |
|
|
|
|
|
|
|
|
st.title("Wallpaper App") |
|
|
|
|
|
|
|
|
st.write("Browse through a collection of beautiful wallpapers and download them!") |
|
|
|
|
|
|
|
|
wallpapers = fetch_wallpapers() |
|
|
|
|
|
|
|
|
for url in wallpapers: |
|
|
img = download_image(url) |
|
|
|
|
|
|
|
|
st.image(img, caption="Wallpaper", use_column_width=True) |
|
|
|
|
|
|
|
|
if st.button(f"Download Wallpaper", key=url): |
|
|
|
|
|
response = requests.get(url) |
|
|
with open("temp_wallpaper.jpg", "wb") as f: |
|
|
f.write(response.content) |
|
|
|
|
|
|
|
|
st.download_button( |
|
|
label="Download this wallpaper", |
|
|
data=open("temp_wallpaper.jpg", "rb").read(), |
|
|
file_name="wallpaper.jpg", |
|
|
mime="image/jpeg", |
|
|
) |
|
|
|
|
|
|
|
|
|