wallpaper / app.py
RaoMamoon's picture
Create app.py
ca48ed6 verified
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