Spaces:
Sleeping
Sleeping
| from fastapi import APIRouter, UploadFile, File , HTTPException, Form | |
| from typing import List , Optional | |
| import asyncio | |
| from src.services.file_proccess import extract_phone_numbers, extract_text_from_file | |
| from src.services.make_call import process_call_list | |
| router = APIRouter() | |
| async def outbound_caller( | |
| numbers_list_str: Optional[str] = Form(None), | |
| file: Optional[UploadFile] = File(None), | |
| prompt: str = Form("") | |
| ) -> List[dict]: | |
| numbers_list = [] | |
| if numbers_list_str: | |
| numbers_list = [i.strip() for i in numbers_list_str.split(",")] | |
| elif file: | |
| text = extract_text_from_file(file) | |
| print("Extracted text from file:\n", text) # Add this | |
| numbers_list = extract_phone_numbers(text) | |
| print("Extracted numbers:", numbers_list) | |
| if not numbers_list: | |
| raise HTTPException(status_code=400, detail="No valid phone numbers found in file") | |
| else: | |
| raise HTTPException(status_code=422, detail="Either 'numbers_list_str' or 'file' is required.") | |
| caller_list = [{"number": number, "prompt": prompt} for number in numbers_list] | |
| # await process_call_list(caller_list) | |
| print(caller_list) | |
| await process_call_list(caller_list) | |
| return caller_list |