Hammad712 commited on
Commit
feabc0d
Β·
verified Β·
1 Parent(s): 209b38f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
2
  import requests
3
  import io
4
  import base64
5
- import time
6
 
7
  # Set the base URL for your FastAPI server
8
  BASE_URL = "https://hammad712-spam.hf.space"
@@ -40,7 +39,6 @@ st.markdown("## Call Test")
40
 
41
  call_number = st.text_input("Enter Caller Number (e.g., +1-555-654-3210 for spam or +1-555-901-2345 for contact):", key="call_number")
42
 
43
- # For this task, we only simulate spam calls if the caller is not found in contacts.
44
  st.markdown("For spam calls, upload the fake audio message below.")
45
  audio_file = st.file_uploader("Upload Fake Audio File", type=["m4a", "wav", "mp3"], key="spam_audio")
46
 
@@ -56,8 +54,7 @@ if st.button("Test Call"):
56
  st.info(f"Call from {call_number} – Ringing")
57
  else:
58
  # No saved contact β†’ treat as spam call.
59
- placeholder = st.empty()
60
- placeholder.markdown(f"**Spam call from {call_number} – Bot replying**")
61
 
62
  # Ensure an audio file is uploaded.
63
  if audio_file is None:
@@ -75,10 +72,9 @@ if st.button("Test Call"):
75
  else:
76
  st.error(f"STT Error: {stt_resp.status_code} {stt_resp.text}")
77
  st.stop()
78
- time.sleep(5) # Wait for 5 seconds
79
- placeholder.markdown(f"**STT:** Transcribed β€˜{transcription}’")
80
 
81
- # ----- Step 2: Call the LLM endpoint using the transcription as input -----
82
  with st.spinner("Processing LLM..."):
83
  llm_payload = {"message": transcription}
84
  llm_resp = requests.post(f"{BASE_URL}/llm", json=llm_payload)
@@ -88,12 +84,11 @@ if st.button("Test Call"):
88
  else:
89
  st.error(f"LLM Error: {llm_resp.status_code} {llm_resp.text}")
90
  st.stop()
91
- time.sleep(10) # Wait additional 10 seconds (total 15 sec from start)
92
- placeholder.markdown(f"**LLM:** Bot says β€˜{llm_reply}’")
93
 
94
- # ----- Step 3: Call the TTS endpoint with a fixed text ("Tell me more!") -----
95
  with st.spinner("Processing TTS..."):
96
- tts_payload = {"text": "Tell me more!"}
97
  tts_resp = requests.post(f"{BASE_URL}/tts", json=tts_payload)
98
  if tts_resp.ok:
99
  tts_data = tts_resp.json()
@@ -101,8 +96,7 @@ if st.button("Test Call"):
101
  else:
102
  st.error(f"TTS Error: {tts_resp.status_code} {tts_resp.text}")
103
  st.stop()
104
- time.sleep(10) # Wait additional 10 seconds (total 25 sec from start)
105
- placeholder.markdown(f"**TTS:** Bot says β€˜Tell me more!’")
106
 
107
  if tts_audio_b64:
108
  audio_bytes = base64.b64decode(tts_audio_b64)
 
2
  import requests
3
  import io
4
  import base64
 
5
 
6
  # Set the base URL for your FastAPI server
7
  BASE_URL = "https://hammad712-spam.hf.space"
 
39
 
40
  call_number = st.text_input("Enter Caller Number (e.g., +1-555-654-3210 for spam or +1-555-901-2345 for contact):", key="call_number")
41
 
 
42
  st.markdown("For spam calls, upload the fake audio message below.")
43
  audio_file = st.file_uploader("Upload Fake Audio File", type=["m4a", "wav", "mp3"], key="spam_audio")
44
 
 
54
  st.info(f"Call from {call_number} – Ringing")
55
  else:
56
  # No saved contact β†’ treat as spam call.
57
+ st.markdown(f"**Spam call from {call_number} – Bot replying**")
 
58
 
59
  # Ensure an audio file is uploaded.
60
  if audio_file is None:
 
72
  else:
73
  st.error(f"STT Error: {stt_resp.status_code} {stt_resp.text}")
74
  st.stop()
75
+ st.markdown(f"**STT:** Transcribed β€˜{transcription}’")
 
76
 
77
+ # ----- Step 2: Call the LLM endpoint using the STT transcription -----
78
  with st.spinner("Processing LLM..."):
79
  llm_payload = {"message": transcription}
80
  llm_resp = requests.post(f"{BASE_URL}/llm", json=llm_payload)
 
84
  else:
85
  st.error(f"LLM Error: {llm_resp.status_code} {llm_resp.text}")
86
  st.stop()
87
+ st.markdown(f"**LLM:** Bot says β€˜{llm_reply}’")
 
88
 
89
+ # ----- Step 3: Call the TTS endpoint with the LLM reply -----
90
  with st.spinner("Processing TTS..."):
91
+ tts_payload = {"text": llm_reply}
92
  tts_resp = requests.post(f"{BASE_URL}/tts", json=tts_payload)
93
  if tts_resp.ok:
94
  tts_data = tts_resp.json()
 
96
  else:
97
  st.error(f"TTS Error: {tts_resp.status_code} {tts_resp.text}")
98
  st.stop()
99
+ st.markdown("**TTS:** Bot audio generated from LLM response")
 
100
 
101
  if tts_audio_b64:
102
  audio_bytes = base64.b64decode(tts_audio_b64)