gskdsrikrishna commited on
Commit
d50d817
Β·
verified Β·
1 Parent(s): dff92e3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("WHATSAPP_API")
8
+
9
+ # API Details
10
+ API_URL = "https://whatsapp-data.p.rapidapi.com/wspicture"
11
+ HEADERS = {
12
+ "x-rapidapi-key": API_KEY,
13
+ "x-rapidapi-host": "whatsapp-data.p.rapidapi.com"
14
+ }
15
+
16
+ # Streamlit UI
17
+ st.set_page_config(page_title="WhatsApp Profile Data", layout="wide")
18
+ st.title("πŸ“± WhatsApp Profile Picture Fetcher")
19
+
20
+ # User Input for Phone Number
21
+ phone_number = st.text_input("Enter Phone Number with Country Code:", "34605797754")
22
+
23
+ if st.button("Fetch Data"):
24
+ with st.spinner("Fetching profile picture..."):
25
+ response = requests.get(API_URL, headers=HEADERS, params={"phone": phone_number})
26
+
27
+ if response.status_code == 200:
28
+ data = response.json()
29
+ st.success("βœ… Data Retrieved Successfully!")
30
+
31
+ # **Display JSON Response**
32
+ st.subheader("πŸ“œ JSON Response")
33
+ st.json(data)
34
+
35
+ # Extract and Display Profile Picture Link
36
+ profile_pic = data.get("profile_picture")
37
+ if profile_pic:
38
+ st.subheader("πŸ–ΌοΈ Profile Picture URL:")
39
+ st.markdown(f"[πŸ”— View Profile Picture]({profile_pic})")
40
+
41
+ # **Download JSON Response**
42
+ json_data = json.dumps(data, indent=4)
43
+ st.subheader("⬇️ Download Data")
44
+ st.download_button(label="Download JSON", data=json_data, file_name=f"{phone_number}_whatsapp_data.json", mime="application/json")
45
+
46
+ else:
47
+ st.error("❌ Failed to retrieve data. Please check the phone number.")
48
+
49
+ # Footer
50
+ st.markdown("---")
51
+ st.caption("Powered by RapidAPI & Streamlit")