Update app.py
Browse files
app.py
CHANGED
|
@@ -7,72 +7,101 @@ BASE_URL = "https://hammad712-spam.hf.space"
|
|
| 7 |
|
| 8 |
st.title("AI Spam Blocker API Tester")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
st.markdown("## Call Test")
|
| 11 |
call_test_type = st.radio("Select Call Test Type", ("Contact Test", "Spam Test"))
|
| 12 |
-
call_number = st.text_input("Enter Caller Number (e.g., +1-555-901-2345 or +1-555-654-3210):")
|
| 13 |
|
| 14 |
if call_test_type == "Spam Test":
|
| 15 |
st.markdown("For spam calls, enter the fake audio message (as text) below.")
|
| 16 |
-
call_message = st.text_input("Enter Fake Audio Message", value="You won a prize!")
|
| 17 |
else:
|
| 18 |
st.markdown("For contact calls, the message is not used because a saved contact returns a ringing response.")
|
| 19 |
-
call_message = st.text_input("Enter Dummy Message (ignored for contact test)", value="dummy", disabled=True)
|
| 20 |
|
| 21 |
if st.button("Test Call"):
|
| 22 |
if not call_number:
|
| 23 |
st.error("Please enter a caller number.")
|
| 24 |
else:
|
| 25 |
-
# For voice calls,
|
| 26 |
-
# We'll create a dummy file (using the call_message as its content)
|
| 27 |
dummy_audio = io.BytesIO(call_message.encode("utf-8"))
|
| 28 |
files = {"audio": ("audio.m4a", dummy_audio, "audio/m4a")}
|
| 29 |
data = {"caller_number": call_number}
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
st.markdown("---")
|
| 40 |
st.markdown("## Text Test")
|
| 41 |
text_test_type = st.radio("Select Text Test Type", ("Contact Test", "Spam Test", "Unknown Test"))
|
| 42 |
text_number = st.text_input("Enter Sender Number for Text Test (e.g., +1-555-901-2345 for contact or other for unsaved):", key="text_number")
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
if st.button("Test Text"):
|
| 46 |
if not text_number or not text_message:
|
| 47 |
st.error("Please enter both a number and a message.")
|
| 48 |
else:
|
| 49 |
payload = {"phone": text_number, "message": text_message}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
try:
|
| 51 |
-
response = requests.post(f"{BASE_URL}/
|
| 52 |
if response.ok:
|
| 53 |
-
|
| 54 |
-
# For primary or spam texts, we show the detail directly.
|
| 55 |
-
if "detail" in data:
|
| 56 |
-
st.success(f"Response: {data['detail']}")
|
| 57 |
-
else:
|
| 58 |
-
st.success("Conversation Result:\n" + data.get("conversation_result", ""))
|
| 59 |
else:
|
| 60 |
st.error(f"Error: {response.status_code} {response.text}")
|
| 61 |
except Exception as e:
|
| 62 |
st.error(f"Exception: {str(e)}")
|
| 63 |
|
| 64 |
-
st.markdown("---")
|
| 65 |
-
st.markdown("## Setup Test")
|
| 66 |
-
if st.button("Start Setup"):
|
| 67 |
-
try:
|
| 68 |
-
response = requests.post(f"{BASE_URL}/setup-call-forwarding")
|
| 69 |
-
if response.ok:
|
| 70 |
-
st.success(f"Response: {response.json()['message']}")
|
| 71 |
-
else:
|
| 72 |
-
st.error(f"Error: {response.status_code} {response.text}")
|
| 73 |
-
except Exception as e:
|
| 74 |
-
st.error(f"Exception: {str(e)}")
|
| 75 |
-
|
| 76 |
st.markdown("---")
|
| 77 |
st.markdown("## Messages History")
|
| 78 |
msg_number = st.text_input("Enter Caller Number to Retrieve Conversation History", key="msg_number")
|
|
@@ -80,12 +109,13 @@ if st.button("Get Messages"):
|
|
| 80 |
if not msg_number:
|
| 81 |
st.error("Please enter a caller number.")
|
| 82 |
else:
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
| 7 |
|
| 8 |
st.title("AI Spam Blocker API Tester")
|
| 9 |
|
| 10 |
+
st.markdown("## Save Contact")
|
| 11 |
+
with st.form("save_contact_form"):
|
| 12 |
+
contact_phone = st.text_input("Enter Contact Phone (e.g., +1-555-901-2345)")
|
| 13 |
+
contact_name = st.text_input("Enter Contact Name (optional)", value="John Doe")
|
| 14 |
+
contact_email = st.text_input("Enter Contact Email (optional)", value="john.doe@example.com")
|
| 15 |
+
submitted = st.form_submit_button("Save Contact")
|
| 16 |
+
|
| 17 |
+
if submitted:
|
| 18 |
+
if not contact_phone:
|
| 19 |
+
st.error("Please enter a contact phone number.")
|
| 20 |
+
else:
|
| 21 |
+
payload = [{
|
| 22 |
+
"phone": contact_phone,
|
| 23 |
+
"name": contact_name if contact_name else None,
|
| 24 |
+
"email": contact_email if contact_email else None
|
| 25 |
+
}]
|
| 26 |
+
with st.spinner("Saving contact..."):
|
| 27 |
+
try:
|
| 28 |
+
response = requests.post(f"{BASE_URL}/contacts", json=payload)
|
| 29 |
+
if response.ok:
|
| 30 |
+
st.success("Contact saved successfully!")
|
| 31 |
+
else:
|
| 32 |
+
st.error(f"Error: {response.status_code} {response.text}")
|
| 33 |
+
except Exception as e:
|
| 34 |
+
st.error(f"Exception: {str(e)}")
|
| 35 |
+
|
| 36 |
+
st.markdown("---")
|
| 37 |
st.markdown("## Call Test")
|
| 38 |
call_test_type = st.radio("Select Call Test Type", ("Contact Test", "Spam Test"))
|
| 39 |
+
call_number = st.text_input("Enter Caller Number (e.g., +1-555-901-2345 or +1-555-654-3210):", key="call_number")
|
| 40 |
|
| 41 |
if call_test_type == "Spam Test":
|
| 42 |
st.markdown("For spam calls, enter the fake audio message (as text) below.")
|
| 43 |
+
call_message = st.text_input("Enter Fake Audio Message", value="You won a prize!", key="call_message")
|
| 44 |
else:
|
| 45 |
st.markdown("For contact calls, the message is not used because a saved contact returns a ringing response.")
|
| 46 |
+
call_message = st.text_input("Enter Dummy Message (ignored for contact test)", value="dummy", key="dummy_message", disabled=True)
|
| 47 |
|
| 48 |
if st.button("Test Call"):
|
| 49 |
if not call_number:
|
| 50 |
st.error("Please enter a caller number.")
|
| 51 |
else:
|
| 52 |
+
# For voice calls, simulate an audio file using the message text.
|
|
|
|
| 53 |
dummy_audio = io.BytesIO(call_message.encode("utf-8"))
|
| 54 |
files = {"audio": ("audio.m4a", dummy_audio, "audio/m4a")}
|
| 55 |
data = {"caller_number": call_number}
|
| 56 |
+
with st.spinner("Processing call..."):
|
| 57 |
+
try:
|
| 58 |
+
response = requests.post(f"{BASE_URL}/process-call", data=data, files=files)
|
| 59 |
+
if response.ok:
|
| 60 |
+
st.success(f"Response: {response.json()['message']}")
|
| 61 |
+
else:
|
| 62 |
+
st.error(f"Error: {response.status_code} {response.text}")
|
| 63 |
+
except Exception as e:
|
| 64 |
+
st.error(f"Exception: {str(e)}")
|
| 65 |
|
| 66 |
st.markdown("---")
|
| 67 |
st.markdown("## Text Test")
|
| 68 |
text_test_type = st.radio("Select Text Test Type", ("Contact Test", "Spam Test", "Unknown Test"))
|
| 69 |
text_number = st.text_input("Enter Sender Number for Text Test (e.g., +1-555-901-2345 for contact or other for unsaved):", key="text_number")
|
| 70 |
+
default_text = "Hi" if text_test_type == "Contact Test" else "Free trip!" if text_test_type == "Spam Test" else "Fix your car!"
|
| 71 |
+
text_message = st.text_input("Enter Text Message", value=default_text, key="text_message")
|
| 72 |
|
| 73 |
if st.button("Test Text"):
|
| 74 |
if not text_number or not text_message:
|
| 75 |
st.error("Please enter both a number and a message.")
|
| 76 |
else:
|
| 77 |
payload = {"phone": text_number, "message": text_message}
|
| 78 |
+
with st.spinner("Processing text message..."):
|
| 79 |
+
try:
|
| 80 |
+
response = requests.post(f"{BASE_URL}/incoming-message", json=payload)
|
| 81 |
+
if response.ok:
|
| 82 |
+
data = response.json()
|
| 83 |
+
if "detail" in data:
|
| 84 |
+
st.success(f"Response: {data['detail']}")
|
| 85 |
+
else:
|
| 86 |
+
st.success("Conversation Result:\n" + data.get("conversation_result", ""))
|
| 87 |
+
else:
|
| 88 |
+
st.error(f"Error: {response.status_code} {response.text}")
|
| 89 |
+
except Exception as e:
|
| 90 |
+
st.error(f"Exception: {str(e)}")
|
| 91 |
+
|
| 92 |
+
st.markdown("---")
|
| 93 |
+
st.markdown("## Setup Test")
|
| 94 |
+
if st.button("Start Setup"):
|
| 95 |
+
with st.spinner("Setting up call forwarding..."):
|
| 96 |
try:
|
| 97 |
+
response = requests.post(f"{BASE_URL}/setup-call-forwarding")
|
| 98 |
if response.ok:
|
| 99 |
+
st.success(f"Response: {response.json()['message']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
else:
|
| 101 |
st.error(f"Error: {response.status_code} {response.text}")
|
| 102 |
except Exception as e:
|
| 103 |
st.error(f"Exception: {str(e)}")
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
st.markdown("---")
|
| 106 |
st.markdown("## Messages History")
|
| 107 |
msg_number = st.text_input("Enter Caller Number to Retrieve Conversation History", key="msg_number")
|
|
|
|
| 109 |
if not msg_number:
|
| 110 |
st.error("Please enter a caller number.")
|
| 111 |
else:
|
| 112 |
+
with st.spinner("Retrieving messages..."):
|
| 113 |
+
try:
|
| 114 |
+
response = requests.get(f"{BASE_URL}/messages/{msg_number}")
|
| 115 |
+
if response.ok:
|
| 116 |
+
data = response.json()
|
| 117 |
+
st.write(data)
|
| 118 |
+
else:
|
| 119 |
+
st.error(f"Error: {response.status_code} {response.text}")
|
| 120 |
+
except Exception as e:
|
| 121 |
+
st.error(f"Exception: {str(e)}")
|