Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,15 +7,15 @@ import os
|
|
7 |
API_KEY = os.getenv("INSTA_API")
|
8 |
|
9 |
# API Details
|
10 |
-
API_URL = "https://
|
11 |
HEADERS = {
|
12 |
"x-rapidapi-key": API_KEY,
|
13 |
-
"x-rapidapi-host": "
|
14 |
}
|
15 |
|
16 |
# Streamlit UI
|
17 |
-
st.set_page_config(page_title="Instagram
|
18 |
-
st.title("πΈ Instagram
|
19 |
|
20 |
# Sidebar for options
|
21 |
st.sidebar.header("Options")
|
@@ -26,52 +26,57 @@ username = st.text_input("Enter Instagram Username:", "mrbeast")
|
|
26 |
|
27 |
if st.button("Fetch Details"):
|
28 |
with st.spinner("Fetching data..."):
|
29 |
-
response = requests.get(API_URL, headers=HEADERS, params={"
|
30 |
-
|
31 |
if response.status_code == 200:
|
32 |
data = response.json()
|
33 |
st.success("β
Data Retrieved Successfully!")
|
34 |
|
35 |
-
# Extracting
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
# Display Links
|
39 |
if links:
|
40 |
-
st.subheader("π
|
41 |
for link in links:
|
42 |
st.markdown(f"[π {link}]({link})")
|
43 |
else:
|
44 |
-
st.info("No links found in the
|
45 |
-
|
46 |
-
# Display Key-Value Pairs
|
47 |
-
st.subheader("π User Details:")
|
48 |
-
text_data = ""
|
49 |
-
for key, value in data.items():
|
50 |
-
st.write(f"**{key}:** {value}")
|
51 |
-
text_data += f"{key}: {value}\n"
|
52 |
|
53 |
# Option to Show Raw JSON Data
|
54 |
if show_json:
|
55 |
st.subheader("π Raw JSON Data")
|
56 |
st.json(data)
|
57 |
|
58 |
-
# **Download Buttons**
|
59 |
-
st.subheader("β¬οΈ Download Data")
|
60 |
-
|
61 |
-
# Download JSON File
|
62 |
-
json_data = json.dumps(data, indent=4)
|
63 |
-
st.download_button(label="Download JSON", data=json_data, file_name=f"{username}_data.json", mime="application/json")
|
64 |
-
|
65 |
-
# Download Text File
|
66 |
-
st.download_button(label="Download Text", data=text_data, file_name=f"{username}_details.txt", mime="text/plain")
|
67 |
-
|
68 |
-
# Download Profile Picture (If available)
|
69 |
-
profile_pic = data.get("profile_picture")
|
70 |
-
if profile_pic:
|
71 |
-
st.image(profile_pic, caption="Profile Picture")
|
72 |
-
img_bytes = requests.get(profile_pic).content
|
73 |
-
st.download_button(label="Download Profile Picture", data=img_bytes, file_name=f"{username}_profile.jpg", mime="image/jpeg")
|
74 |
-
|
75 |
else:
|
76 |
st.error("β Failed to retrieve data. Please check the username.")
|
77 |
|
|
|
7 |
API_KEY = os.getenv("INSTA_API")
|
8 |
|
9 |
# API Details
|
10 |
+
API_URL = "https://instagram230.p.rapidapi.com/user/details"
|
11 |
HEADERS = {
|
12 |
"x-rapidapi-key": API_KEY,
|
13 |
+
"x-rapidapi-host": "instagram230.p.rapidapi.com"
|
14 |
}
|
15 |
|
16 |
# Streamlit UI
|
17 |
+
st.set_page_config(page_title="Instagram User Details", layout="wide")
|
18 |
+
st.title("πΈ Instagram User Details")
|
19 |
|
20 |
# Sidebar for options
|
21 |
st.sidebar.header("Options")
|
|
|
26 |
|
27 |
if st.button("Fetch Details"):
|
28 |
with st.spinner("Fetching data..."):
|
29 |
+
response = requests.get(API_URL, headers=HEADERS, params={"username": username})
|
30 |
+
|
31 |
if response.status_code == 200:
|
32 |
data = response.json()
|
33 |
st.success("β
Data Retrieved Successfully!")
|
34 |
|
35 |
+
# Extracting and Displaying Structured Information
|
36 |
+
st.subheader("π User Profile Details")
|
37 |
+
|
38 |
+
if "full_name" in data:
|
39 |
+
st.write(f"**Full Name:** {data['full_name']}")
|
40 |
+
|
41 |
+
if "username" in data:
|
42 |
+
st.write(f"**Username:** @{data['username']}")
|
43 |
+
|
44 |
+
if "biography" in data and data["biography"]:
|
45 |
+
st.write(f"**Bio:** {data['biography']}")
|
46 |
+
|
47 |
+
if "follower_count" in data:
|
48 |
+
st.write(f"**Followers:** {data['follower_count']}")
|
49 |
+
|
50 |
+
if "following_count" in data:
|
51 |
+
st.write(f"**Following:** {data['following_count']}")
|
52 |
+
|
53 |
+
# Display Profile Picture
|
54 |
+
profile_pic = data.get("profile_pic_url_hd") or data.get("profile_pic_url")
|
55 |
+
if profile_pic:
|
56 |
+
st.image(profile_pic, caption="Profile Picture")
|
57 |
+
img_bytes = requests.get(profile_pic).content
|
58 |
+
st.download_button(label="Download Profile Picture", data=img_bytes, file_name=f"{username}_profile.jpg", mime="image/jpeg")
|
59 |
+
|
60 |
+
# Extracting and Displaying Links
|
61 |
+
links = []
|
62 |
+
if "external_url" in data and data["external_url"]:
|
63 |
+
links.append(data["external_url"])
|
64 |
+
|
65 |
+
if "bio_links" in data and isinstance(data["bio_links"], list):
|
66 |
+
links.extend([link["url"] for link in data["bio_links"] if "url" in link and link["url"]])
|
67 |
|
|
|
68 |
if links:
|
69 |
+
st.subheader("π Relevant Links:")
|
70 |
for link in links:
|
71 |
st.markdown(f"[π {link}]({link})")
|
72 |
else:
|
73 |
+
st.info("No links found in the profile.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# Option to Show Raw JSON Data
|
76 |
if show_json:
|
77 |
st.subheader("π Raw JSON Data")
|
78 |
st.json(data)
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
else:
|
81 |
st.error("β Failed to retrieve data. Please check the username.")
|
82 |
|