add filler
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import shutil
|
|
| 7 |
import uuid
|
| 8 |
|
| 9 |
# Ensure sibling module fluency is discoverable
|
| 10 |
-
#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__))))
|
| 11 |
|
| 12 |
from fluency.fluency_api import main as analyze_fluency_main
|
| 13 |
from tone_modulation.tone_api import main as analyze_tone_main
|
|
@@ -19,26 +19,6 @@ from ves.ves import calc_voice_engagement_score
|
|
| 19 |
from transcribe import transcribe_audio
|
| 20 |
from filler_count.filler_score import analyze_fillers
|
| 21 |
|
| 22 |
-
import logging
|
| 23 |
-
|
| 24 |
-
# Configure logging
|
| 25 |
-
logging.basicConfig(
|
| 26 |
-
level=logging.INFO, # Or DEBUG for more verbose logs
|
| 27 |
-
format="%(asctime)s - %(levelname)s - %(message)s",
|
| 28 |
-
handlers=[
|
| 29 |
-
logging.StreamHandler(sys.stdout)
|
| 30 |
-
]
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
logger = logging.getLogger(__name__)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
app = FastAPI()
|
| 43 |
|
| 44 |
app.add_middleware(
|
|
@@ -49,47 +29,6 @@ app.add_middleware(
|
|
| 49 |
allow_headers=["*"],
|
| 50 |
)
|
| 51 |
|
| 52 |
-
@app.get("/")
|
| 53 |
-
def home():
|
| 54 |
-
return {"status": "Running"}
|
| 55 |
-
|
| 56 |
-
@app.get("/health")
|
| 57 |
-
def health_check():
|
| 58 |
-
return {"status": "ok"}
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
# this will just rturen that audio file is being ready for analysis
|
| 62 |
-
@app.post("/audio_status/")
|
| 63 |
-
async def audio_status(file: UploadFile):
|
| 64 |
-
"""
|
| 65 |
-
Endpoint to check the status of an uploaded audio file (.wav or .mp3).
|
| 66 |
-
"""
|
| 67 |
-
if not file.filename.endswith(('.wav', '.mp3')):
|
| 68 |
-
raise HTTPException(status_code=400, detail="Invalid file type. Only .wav and .mp3 files are supported.")
|
| 69 |
-
|
| 70 |
-
# Generate a safe temporary file path
|
| 71 |
-
temp_filename = f"temp_{uuid.uuid4()}{os.path.splitext(file.filename)[1]}"
|
| 72 |
-
temp_dir = "temp_uploads"
|
| 73 |
-
temp_filepath = os.path.join(temp_dir, temp_filename)
|
| 74 |
-
os.makedirs(temp_dir, exist_ok=True)
|
| 75 |
-
|
| 76 |
-
try:
|
| 77 |
-
# Save uploaded file
|
| 78 |
-
with open(temp_filepath, "wb") as buffer:
|
| 79 |
-
shutil.copyfileobj(file.file, buffer)
|
| 80 |
-
|
| 81 |
-
return JSONResponse(content={"status": "File is ready for analysis"})
|
| 82 |
-
|
| 83 |
-
except Exception as e:
|
| 84 |
-
raise HTTPException(status_code=500, detail=f"File status check failed: {str(e)}")
|
| 85 |
-
|
| 86 |
-
finally:
|
| 87 |
-
# Clean up temporary file
|
| 88 |
-
if os.path.exists(temp_filepath):
|
| 89 |
-
os.remove(temp_filepath)
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
@app.post("/analyze_fluency/")
|
| 94 |
async def analyze_fluency(file: UploadFile):
|
| 95 |
# idk if we can use pydantic model here If we need I can add later
|
|
@@ -120,74 +59,38 @@ async def analyze_fluency(file: UploadFile):
|
|
| 120 |
if os.path.exists(temp_filepath):
|
| 121 |
os.remove(temp_filepath)
|
| 122 |
|
| 123 |
-
# @app.post('/analyze_tone/')
|
| 124 |
-
# async def analyze_tone(file: UploadFile):
|
| 125 |
-
# """
|
| 126 |
-
# Endpoint to analyze tone of an uploaded audio file (.wav or .mp3).
|
| 127 |
-
# """
|
| 128 |
-
# if not file.filename.endswith(('.wav', '.mp3')):
|
| 129 |
-
# raise HTTPException(status_code=400, detail="Invalid file type. Only .wav and .mp3 files are supported.")
|
| 130 |
-
|
| 131 |
-
# # Generate a safe temporary file path
|
| 132 |
-
# temp_filename = f"temp_{uuid.uuid4()}{os.path.splitext(file.filename)[1]}"
|
| 133 |
-
# temp_dir = "temp_uploads"
|
| 134 |
-
# temp_filepath = os.path.join(temp_dir, temp_filename)
|
| 135 |
-
# os.makedirs(temp_dir, exist_ok=True)
|
| 136 |
-
|
| 137 |
-
# try:
|
| 138 |
-
# # Save uploaded file
|
| 139 |
-
# with open(temp_filepath, "wb") as buffer:
|
| 140 |
-
# shutil.copyfileobj(file.file, buffer)
|
| 141 |
-
|
| 142 |
-
# # Analyze tone using your custom function
|
| 143 |
-
# result = analyze_tone_main(temp_filepath)
|
| 144 |
-
|
| 145 |
-
# return JSONResponse(content=result)
|
| 146 |
-
|
| 147 |
-
# except Exception as e:
|
| 148 |
-
# raise HTTPException(status_code=500, detail=f"Tone analysis failed: {str(e)}")
|
| 149 |
-
|
| 150 |
-
# finally:
|
| 151 |
-
# # Clean up temporary file
|
| 152 |
-
# if os.path.exists(temp_filepath):
|
| 153 |
-
# os.remove(temp_filepath)
|
| 154 |
-
|
| 155 |
@app.post('/analyze_tone/')
|
| 156 |
async def analyze_tone(file: UploadFile):
|
| 157 |
-
|
| 158 |
-
|
|
|
|
| 159 |
if not file.filename.endswith(('.wav', '.mp3')):
|
| 160 |
-
logger.warning("Invalid file type received")
|
| 161 |
raise HTTPException(status_code=400, detail="Invalid file type. Only .wav and .mp3 files are supported.")
|
| 162 |
|
|
|
|
| 163 |
temp_filename = f"temp_{uuid.uuid4()}{os.path.splitext(file.filename)[1]}"
|
| 164 |
temp_dir = "temp_uploads"
|
| 165 |
temp_filepath = os.path.join(temp_dir, temp_filename)
|
| 166 |
os.makedirs(temp_dir, exist_ok=True)
|
| 167 |
|
| 168 |
try:
|
| 169 |
-
|
| 170 |
with open(temp_filepath, "wb") as buffer:
|
| 171 |
shutil.copyfileobj(file.file, buffer)
|
| 172 |
|
| 173 |
-
|
| 174 |
result = analyze_tone_main(temp_filepath)
|
| 175 |
-
logger.info("Tone analysis completed successfully")
|
| 176 |
|
| 177 |
return JSONResponse(content=result)
|
| 178 |
|
| 179 |
except Exception as e:
|
| 180 |
-
logger.error(f"Tone analysis failed: {str(e)}", exc_info=True)
|
| 181 |
raise HTTPException(status_code=500, detail=f"Tone analysis failed: {str(e)}")
|
| 182 |
|
| 183 |
finally:
|
|
|
|
| 184 |
if os.path.exists(temp_filepath):
|
| 185 |
-
logger.info(f"Cleaning up temporary file: {temp_filepath}")
|
| 186 |
os.remove(temp_filepath)
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
@app.post('/analyze_vcs/')
|
| 192 |
async def analyze_vcs(file: UploadFile):
|
| 193 |
"""
|
|
@@ -454,6 +357,7 @@ async def analyze_all(file: UploadFile):
|
|
| 454 |
voice_confidence_result = analyze_voice_confidence_main(temp_filepath)
|
| 455 |
vps_result = analyze_vps_main(temp_filepath)
|
| 456 |
ves_result = calc_voice_engagement_score(temp_filepath)
|
|
|
|
| 457 |
transcript = transcribe_audio(temp_filepath)
|
| 458 |
|
| 459 |
# Combine results into a single response
|
|
@@ -465,6 +369,7 @@ async def analyze_all(file: UploadFile):
|
|
| 465 |
"voice_confidence": voice_confidence_result,
|
| 466 |
"vps": vps_result,
|
| 467 |
"ves": ves_result,
|
|
|
|
| 468 |
"transcript": transcript
|
| 469 |
}
|
| 470 |
|
|
@@ -477,7 +382,3 @@ async def analyze_all(file: UploadFile):
|
|
| 477 |
# Clean up temporary file
|
| 478 |
if os.path.exists(temp_filepath):
|
| 479 |
os.remove(temp_filepath)
|
| 480 |
-
|
| 481 |
-
# if __name__ == "__main__":
|
| 482 |
-
# import uvicorn
|
| 483 |
-
# uvicorn.run("main:app", host="0.0.0.0", port=int(os.environ.get("PORT", 10000)), reload=False)
|
|
|
|
| 7 |
import uuid
|
| 8 |
|
| 9 |
# Ensure sibling module fluency is discoverable
|
| 10 |
+
#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
| 11 |
|
| 12 |
from fluency.fluency_api import main as analyze_fluency_main
|
| 13 |
from tone_modulation.tone_api import main as analyze_tone_main
|
|
|
|
| 19 |
from transcribe import transcribe_audio
|
| 20 |
from filler_count.filler_score import analyze_fillers
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
app = FastAPI()
|
| 23 |
|
| 24 |
app.add_middleware(
|
|
|
|
| 29 |
allow_headers=["*"],
|
| 30 |
)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
@app.post("/analyze_fluency/")
|
| 33 |
async def analyze_fluency(file: UploadFile):
|
| 34 |
# idk if we can use pydantic model here If we need I can add later
|
|
|
|
| 59 |
if os.path.exists(temp_filepath):
|
| 60 |
os.remove(temp_filepath)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
@app.post('/analyze_tone/')
|
| 63 |
async def analyze_tone(file: UploadFile):
|
| 64 |
+
"""
|
| 65 |
+
Endpoint to analyze tone of an uploaded audio file (.wav or .mp3).
|
| 66 |
+
"""
|
| 67 |
if not file.filename.endswith(('.wav', '.mp3')):
|
|
|
|
| 68 |
raise HTTPException(status_code=400, detail="Invalid file type. Only .wav and .mp3 files are supported.")
|
| 69 |
|
| 70 |
+
# Generate a safe temporary file path
|
| 71 |
temp_filename = f"temp_{uuid.uuid4()}{os.path.splitext(file.filename)[1]}"
|
| 72 |
temp_dir = "temp_uploads"
|
| 73 |
temp_filepath = os.path.join(temp_dir, temp_filename)
|
| 74 |
os.makedirs(temp_dir, exist_ok=True)
|
| 75 |
|
| 76 |
try:
|
| 77 |
+
# Save uploaded file
|
| 78 |
with open(temp_filepath, "wb") as buffer:
|
| 79 |
shutil.copyfileobj(file.file, buffer)
|
| 80 |
|
| 81 |
+
# Analyze tone using your custom function
|
| 82 |
result = analyze_tone_main(temp_filepath)
|
|
|
|
| 83 |
|
| 84 |
return JSONResponse(content=result)
|
| 85 |
|
| 86 |
except Exception as e:
|
|
|
|
| 87 |
raise HTTPException(status_code=500, detail=f"Tone analysis failed: {str(e)}")
|
| 88 |
|
| 89 |
finally:
|
| 90 |
+
# Clean up temporary file
|
| 91 |
if os.path.exists(temp_filepath):
|
|
|
|
| 92 |
os.remove(temp_filepath)
|
| 93 |
|
|
|
|
|
|
|
|
|
|
| 94 |
@app.post('/analyze_vcs/')
|
| 95 |
async def analyze_vcs(file: UploadFile):
|
| 96 |
"""
|
|
|
|
| 357 |
voice_confidence_result = analyze_voice_confidence_main(temp_filepath)
|
| 358 |
vps_result = analyze_vps_main(temp_filepath)
|
| 359 |
ves_result = calc_voice_engagement_score(temp_filepath)
|
| 360 |
+
filler_count = analyze_fillers(temp_filepath) # Assuming this function returns a dict with filler count
|
| 361 |
transcript = transcribe_audio(temp_filepath)
|
| 362 |
|
| 363 |
# Combine results into a single response
|
|
|
|
| 369 |
"voice_confidence": voice_confidence_result,
|
| 370 |
"vps": vps_result,
|
| 371 |
"ves": ves_result,
|
| 372 |
+
"filler_words": filler_count,
|
| 373 |
"transcript": transcript
|
| 374 |
}
|
| 375 |
|
|
|
|
| 382 |
# Clean up temporary file
|
| 383 |
if os.path.exists(temp_filepath):
|
| 384 |
os.remove(temp_filepath)
|
|
|
|
|
|
|
|
|
|
|
|