Spaces:
Sleeping
Sleeping
Commit
·
322549d
1
Parent(s):
88f1169
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import threading
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Load environment variables from .env file
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Retrieve environment variables
|
| 11 |
+
auth_token = os.getenv('auth_token')
|
| 12 |
+
phone_number_id = os.getenv('phone_number_id')
|
| 13 |
+
assistant_id = os.getenv('assistant_id')
|
| 14 |
+
|
| 15 |
+
def make_call(phone_number):
|
| 16 |
+
headers = {
|
| 17 |
+
'Authorization': f'Bearer {auth_token}',
|
| 18 |
+
'Content-Type': 'application/json',
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
data = {
|
| 22 |
+
'assistantId': assistant_id,
|
| 23 |
+
'phoneNumberId': phone_number_id,
|
| 24 |
+
'customer': {
|
| 25 |
+
'number': phone_number,
|
| 26 |
+
},
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
response = requests.post(
|
| 30 |
+
'https://api.vapi.ai/call/phone', headers=headers, json=data)
|
| 31 |
+
|
| 32 |
+
if response.status_code == 201:
|
| 33 |
+
return f'Call to {phone_number} created successfully'
|
| 34 |
+
else:
|
| 35 |
+
return f'Failed to create call to {phone_number}'
|
| 36 |
+
|
| 37 |
+
def main():
|
| 38 |
+
st.title('Outbound Calls Using VAPI.AI')
|
| 39 |
+
|
| 40 |
+
phone_numbers_input = st.text_input('Enter phone numbers (e.g., +62187461, +198724914):')
|
| 41 |
+
phone_numbers = [num.strip() for num in phone_numbers_input.split(',') if num.strip()]
|
| 42 |
+
|
| 43 |
+
if st.button('Make Calls'):
|
| 44 |
+
threads = []
|
| 45 |
+
for number in phone_numbers:
|
| 46 |
+
thread = threading.Thread(target=make_call, args=(number,))
|
| 47 |
+
thread.start()
|
| 48 |
+
threads.append(thread)
|
| 49 |
+
|
| 50 |
+
for thread in threads:
|
| 51 |
+
thread.join()
|
| 52 |
+
|
| 53 |
+
st.success('Calls initiated successfully')
|
| 54 |
+
|
| 55 |
+
if __name__ == '__main__':
|
| 56 |
+
main()
|