Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
-
from bs4 import BeautifulSoup
|
3 |
import requests
|
4 |
-
from selenium import webdriver
|
5 |
import time
|
6 |
-
import io
|
7 |
from PIL import Image
|
|
|
8 |
|
9 |
def download_instagram_image(link):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
with webdriver.Chrome('chromedriver', options=options) as driver:
|
16 |
-
driver.get(link)
|
17 |
-
time.sleep(2) # Allow time for the page to load
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
image.save(f"instagram_{int(time.time())}.png")
|
28 |
-
st.success('Image downloaded successfully!')
|
29 |
-
else:
|
30 |
-
st.error('Could not find the image on the provided URL.')
|
31 |
|
32 |
def main():
|
33 |
st.title("Instagram Image Downloader")
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import requests
|
|
|
3 |
import time
|
|
|
4 |
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
def download_instagram_image(link):
|
8 |
+
response = requests.get(link)
|
9 |
+
|
10 |
+
if response.status_code == 200:
|
11 |
+
data = response.json()
|
12 |
+
img_url = data["graphql"]["shortcode_media"]["display_url"]
|
|
|
|
|
|
|
13 |
|
14 |
+
img_response = requests.get(img_url)
|
15 |
+
img_data = BytesIO(img_response.content)
|
16 |
+
|
17 |
+
image = Image.open(img_data)
|
18 |
+
image.save(f"instagram_{int(time.time())}.png")
|
19 |
+
st.success('Image downloaded successfully!')
|
20 |
+
else:
|
21 |
+
st.error('Error fetching Instagram data. Please check the provided URL.')
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def main():
|
24 |
st.title("Instagram Image Downloader")
|