gskdsrikrishna's picture
Update app.py
38ce944 verified
raw
history blame
1.72 kB
import streamlit as st
import requests
import json
import os
# Load API Key from Hugging Face Secrets
API_KEY = os.getenv("WHATS_API")
# API Details
API_URL = "https://whatsapp-data.p.rapidapi.com/wspicture"
HEADERS = {
"x-rapidapi-key": API_KEY,
"x-rapidapi-host": "whatsapp-data.p.rapidapi.com"
}
# Streamlit UI
st.set_page_config(page_title="WhatsApp Profile Data", layout="wide")
st.title("πŸ“± WhatsApp Profile Picture Fetcher")
# User Input for Phone Number
phone_number = st.text_input("Enter Phone Number with Country Code:", "34605797754")
if st.button("Fetch Data"):
with st.spinner("Fetching profile picture..."):
response = requests.get(API_URL, headers=HEADERS, params={"phone": phone_number})
if response.status_code == 200:
data = response.json()
st.success("βœ… Data Retrieved Successfully!")
# **Display JSON Response**
st.subheader("πŸ“œ JSON Response")
st.json(data)
# Extract and Display Profile Picture Link
profile_pic = data.get("profile_picture")
if profile_pic:
st.subheader("πŸ–ΌοΈ Profile Picture URL:")
st.markdown(f"[πŸ”— View Profile Picture]({profile_pic})")
# **Download JSON Response**
json_data = json.dumps(data, indent=4)
st.subheader("⬇️ Download Data")
st.download_button(label="Download JSON", data=json_data, file_name=f"{phone_number}_whatsapp_data.json", mime="application/json")
else:
st.error("❌ Failed to retrieve data. Please check the phone number.")
# Footer
st.markdown("---")
st.caption("Powered by RapidAPI & Streamlit")