File size: 2,808 Bytes
248da8f
 
 
 
 
 
fd4db75
248da8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import streamlit as st
import requests
import json
import os

# Load API Key from Hugging Face Secrets
API_KEY = os.getenv("INSTA_API")

# API Details
API_URL = "https://instagram230.p.rapidapi.com/user/details"
HEADERS = {
    "x-rapidapi-key": API_KEY,
    "x-rapidapi-host": "instagram230.p.rapidapi.com"
}

# Streamlit UI
st.set_page_config(page_title="Instagram User Details", layout="wide")
st.title("πŸ“Έ Instagram User Details")

# Sidebar for options
st.sidebar.header("Options")
show_json = st.sidebar.checkbox("Show Raw JSON Response", value=False)

# User Input
username = st.text_input("Enter Instagram Username:", "joerogan")

if st.button("Fetch Details"):
    with st.spinner("Fetching data..."):
        response = requests.get(API_URL, headers=HEADERS, params={"username": username})
        
        if response.status_code == 200:
            data = response.json()
            st.success("βœ… Data Retrieved Successfully!")

            # Extracting Links
            links = [value for key, value in data.items() if isinstance(value, str) and value.startswith("http")]

            # Display Links
            if links:
                st.subheader("πŸ”— Extracted Links:")
                for link in links:
                    st.markdown(f"[πŸ”— {link}]({link})")
            else:
                st.info("No links found in the response.")

            # Display Key-Value Pairs
            st.subheader("πŸ“„ User Details:")
            text_data = ""
            for key, value in data.items():
                st.write(f"**{key}:** {value}")
                text_data += f"{key}: {value}\n"

            # Option to Show Raw JSON Data
            if show_json:
                st.subheader("πŸ“œ Raw JSON Data")
                st.json(data)

            # **Download Buttons**
            st.subheader("⬇️ Download Data")
            
            # Download JSON File
            json_data = json.dumps(data, indent=4)
            st.download_button(label="Download JSON", data=json_data, file_name=f"{username}_data.json", mime="application/json")

            # Download Text File
            st.download_button(label="Download Text", data=text_data, file_name=f"{username}_details.txt", mime="text/plain")

            # Download Image (If available)
            profile_pic = data.get("profile_picture")
            if profile_pic:
                st.image(profile_pic, caption="Profile Picture")
                img_bytes = requests.get(profile_pic).content
                st.download_button(label="Download Profile Picture", data=img_bytes, file_name=f"{username}_profile.jpg", mime="image/jpeg")

        else:
            st.error("❌ Failed to retrieve data. Please check the username.")

# Footer
st.markdown("---")
st.caption("Powered by RapidAPI & Streamlit")