gskdsrikrishna commited on
Commit
248da8f
Β·
verified Β·
1 Parent(s): 631f82f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import json
4
+ import os
5
+
6
+ # Load API Key from Hugging Face Secrets
7
+ API_KEY = os.getenv("INSTAGRAM_API_KEY")
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")
22
+ show_json = st.sidebar.checkbox("Show Raw JSON Response", value=False)
23
+
24
+ # User Input
25
+ username = st.text_input("Enter Instagram Username:", "joerogan")
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 Links
36
+ links = [value for key, value in data.items() if isinstance(value, str) and value.startswith("http")]
37
+
38
+ # Display Links
39
+ if links:
40
+ st.subheader("πŸ”— Extracted Links:")
41
+ for link in links:
42
+ st.markdown(f"[πŸ”— {link}]({link})")
43
+ else:
44
+ st.info("No links found in the response.")
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 Image (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
+
78
+ # Footer
79
+ st.markdown("---")
80
+ st.caption("Powered by RapidAPI & Streamlit")