RaoMamoon commited on
Commit
ca48ed6
·
verified ·
1 Parent(s): 452d218

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import requests
4
+ from PIL import Image
5
+ from io import BytesIO
6
+
7
+ # Function to fetch wallpapers
8
+ def fetch_wallpapers():
9
+ # You can replace this with your own list of image URLs.
10
+ wallpaper_urls = [
11
+ "https://example.com/wallpaper1.jpg",
12
+ "https://example.com/wallpaper2.jpg",
13
+ "https://example.com/wallpaper3.jpg",
14
+ # Add more URLs
15
+ ]
16
+ return wallpaper_urls
17
+
18
+ # Function to download the image from URL
19
+ def download_image(url):
20
+ response = requests.get(url)
21
+ img = Image.open(BytesIO(response.content))
22
+ return img
23
+
24
+ # Title of the app
25
+ st.title("Wallpaper App")
26
+
27
+ # Displaying a description
28
+ st.write("Browse through a collection of beautiful wallpapers and download them!")
29
+
30
+ # Fetching wallpapers
31
+ wallpapers = fetch_wallpapers()
32
+
33
+ # Display wallpapers with a download button
34
+ for url in wallpapers:
35
+ img = download_image(url)
36
+
37
+ # Display the image
38
+ st.image(img, caption="Wallpaper", use_column_width=True)
39
+
40
+ # Download button
41
+ if st.button(f"Download Wallpaper", key=url):
42
+ # Save the image temporarily
43
+ response = requests.get(url)
44
+ with open("temp_wallpaper.jpg", "wb") as f:
45
+ f.write(response.content)
46
+
47
+ # Let the user download the image
48
+ st.download_button(
49
+ label="Download this wallpaper",
50
+ data=open("temp_wallpaper.jpg", "rb").read(),
51
+ file_name="wallpaper.jpg",
52
+ mime="image/jpeg",
53
+ )
54
+
55
+ # You can also add categories or search functionality if needed