Hammad712 commited on
Commit
5874100
·
verified ·
1 Parent(s): 46276fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import requests
3
  import io
 
4
 
5
  # Set the base URL for your FastAPI server
6
  BASE_URL = "https://hammad712-spam.hf.space"
@@ -43,7 +44,6 @@ if call_test_type == "Spam Test":
43
  audio_file = st.file_uploader("Upload Fake Audio File", type=["m4a", "wav", "mp3"])
44
  else:
45
  st.markdown("For contact calls, the message is not used because a saved contact returns a ringing response.")
46
- # For a contact test, we'll create a dummy audio message.
47
  dummy_message = "dummy"
48
  audio_file = None
49
 
@@ -51,7 +51,6 @@ if st.button("Test Call"):
51
  if not call_number:
52
  st.error("Please enter a caller number.")
53
  else:
54
- # For Contact Test, use a dummy audio message; for Spam Test, use the uploaded audio file.
55
  if call_test_type == "Spam Test":
56
  if audio_file is None:
57
  st.error("Please upload a fake audio file for the spam test.")
@@ -59,7 +58,6 @@ if st.button("Test Call"):
59
  dummy_audio = audio_file.read()
60
  files = {"audio": (audio_file.name, io.BytesIO(dummy_audio), audio_file.type)}
61
  else:
62
- # Create a dummy audio file using dummy_message for contact test.
63
  dummy_audio = io.BytesIO(dummy_message.encode("utf-8"))
64
  files = {"audio": ("audio.m4a", dummy_audio, "audio/m4a")}
65
  data = {"caller_number": call_number}
@@ -68,6 +66,23 @@ if st.button("Test Call"):
68
  response = requests.post(f"{BASE_URL}/process-call", data=data, files=files)
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:
 
1
  import streamlit as st
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"
 
44
  audio_file = st.file_uploader("Upload Fake Audio File", type=["m4a", "wav", "mp3"])
45
  else:
46
  st.markdown("For contact calls, the message is not used because a saved contact returns a ringing response.")
 
47
  dummy_message = "dummy"
48
  audio_file = None
49
 
 
51
  if not call_number:
52
  st.error("Please enter a caller number.")
53
  else:
 
54
  if call_test_type == "Spam Test":
55
  if audio_file is None:
56
  st.error("Please upload a fake audio file for the spam test.")
 
58
  dummy_audio = audio_file.read()
59
  files = {"audio": (audio_file.name, io.BytesIO(dummy_audio), audio_file.type)}
60
  else:
 
61
  dummy_audio = io.BytesIO(dummy_message.encode("utf-8"))
62
  files = {"audio": ("audio.m4a", dummy_audio, "audio/m4a")}
63
  data = {"caller_number": call_number}
 
66
  response = requests.post(f"{BASE_URL}/process-call", data=data, files=files)
67
  if response.ok:
68
  st.success(f"Response: {response.json()['message']}")
69
+ # After process-call is successful, get the audio reply
70
+ with st.spinner("Retrieving audio response..."):
71
+ audio_reply_resp = requests.get(f"{BASE_URL}/audio-reply/{call_number}")
72
+ if audio_reply_resp.ok:
73
+ audio_data = audio_reply_resp.json()
74
+ st.markdown("### Audio Reply Details")
75
+ st.write("**STT Response:**", audio_data.get("stt_response", ""))
76
+ st.write("**LLM Reply:**", audio_data.get("llm_reply", ""))
77
+ # Decode the base64 audio and display an audio player
78
+ audio_b64 = audio_data.get("audio_reply", "")
79
+ if audio_b64:
80
+ audio_bytes = base64.b64decode(audio_b64)
81
+ st.audio(audio_bytes, format="audio/wav")
82
+ else:
83
+ st.info("No audio reply available.")
84
+ else:
85
+ st.error(f"Error retrieving audio reply: {audio_reply_resp.status_code} {audio_reply_resp.text}")
86
  else:
87
  st.error(f"Error: {response.status_code} {response.text}")
88
  except Exception as e: