Spaces:
Running
Running
Add DAM voice biomarker inference app
Browse filesFiles changed (4)
- README.md+8-7
- app.pyAdded+110
- packages.txtAdded+1
- requirements.txtAdded+6
12345678910111213---title: Dam Inferenceemoji: 🏢colorFrom: pinkcolorTo: pinksdk: gradiosdk_version: 6.12.0app_file: app.pypinned: falseshort_description: Voice biomarker inference using KintsugiHealth/DAM---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference1234567891011121314---title: Loop Mind DAM Inferenceemoji: 🧬colorFrom: indigocolorTo: purplesdk: gradiosdk_version: 5.23.0app_file: app.pypinned: falselicense: apache-2.0---Voice biomarker inference for Loop Mind using KintsugiHealth/DAM.Returns depression/anxiety severity scores from acoustic voice features.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110"""Loop Mind — DAM Voice Biomarker Inference Space================================================Wraps KintsugiHealth/DAM for voice biomarker analysis.Accepts audio, returns depression/anxiety severity scores.
Deployed as a Hugging Face Space (Gradio).Called by the Loop Mind /voice-biomarker Supabase Edge Function."""
import sysimport osimport subprocessimport warningsimport json
import gradio as grimport torchimport torchaudio
warnings.filterwarnings("ignore")
# Download the DAM model on first runif not os.path.exists("dam"): print("Downloading KintsugiHealth/DAM model (~1GB)...") subprocess.run(["git", "clone", "https://huggingface.co/KintsugiHealth/dam"])
sys.path.append(os.path.abspath("dam"))
print("Loading DAM pipeline...")try: from pipeline import Pipeline dam_pipeline = Pipeline() print("DAM model loaded successfully.")except Exception as e: print(f"Failed to load DAM model: {e}") dam_pipeline = None
DEP_LABELS = {0: "none", 1: "mild-moderate", 2: "severe"}ANX_LABELS = {0: "none", 1: "mild", 2: "moderate", 3: "severe"}
def analyze_audio(audio_filepath: str) -> str: """ Accepts an audio file path, runs DAM inference, returns JSON string with depression/anxiety scores (both quantized and raw). """ if audio_filepath is None: return json.dumps({"error": "No audio provided"})
if dam_pipeline is None: return json.dumps({"error": "Model not loaded"})
try: # Pre-process: convert to mono if needed waveform, sample_rate = torchaudio.load(audio_filepath) if waveform.shape[0] > 1: waveform = torch.mean(waveform, dim=0, keepdim=True) audio_filepath = "temp_mono.wav" torchaudio.save(audio_filepath, waveform, sample_rate)
# Run inference (both quantized and raw) res_q = dam_pipeline.run_on_file(audio_filepath, quantize=True) res_r = dam_pipeline.run_on_file(audio_filepath, quantize=False)
# Extract and normalize scores dep_q = int(res_q.get("depression", 0).item() if hasattr(res_q.get("depression", 0), "item") else res_q.get("depression", 0)) anx_q = int(res_q.get("anxiety", 0).item() if hasattr(res_q.get("anxiety", 0), "item") else res_q.get("anxiety", 0)) dep_r = float(res_r.get("depression", 0.0).item() if hasattr(res_r.get("depression", 0.0), "item") else res_r.get("depression", 0.0)) anx_r = float(res_r.get("anxiety", 0.0).item() if hasattr(res_r.get("anxiety", 0.0), "item") else res_r.get("anxiety", 0.0))
result = { "depression": dep_q, "depression_label": DEP_LABELS.get(dep_q, "unknown"), "anxiety": anx_q, "anxiety_label": ANX_LABELS.get(anx_q, "unknown"), "raw_depression": round(dep_r, 4), "raw_anxiety": round(anx_r, 4), "model": "KintsugiHealth/dam", }
return json.dumps(result)
except Exception as e: return json.dumps({"error": str(e)})
# Clean up temp file after processingdef analyze_and_cleanup(audio_filepath: str) -> str: result = analyze_audio(audio_filepath) # Delete temp mono file if created if os.path.exists("temp_mono.wav"): try: os.unlink("temp_mono.wav") except OSError: pass return result
demo = gr.Interface( fn=analyze_and_cleanup, inputs=gr.Audio(type="filepath", label="Upload audio or record (30+ seconds recommended)"), outputs=gr.Textbox(label="Analysis Result (JSON)", lines=10), title="Loop Mind — Voice Biomarker Analysis", description="Powered by KintsugiHealth/DAM. Returns depression and anxiety severity scores from voice acoustic features. For research and wellness tracking only — not a clinical diagnosis.", theme="soft",)
demo.launch()1ffmpeg123456torchtorchaudiotransformerssoundfilepefttorchcodecREADME.md+8-7
app.pyAdded+110
packages.txtAdded+1
requirements.txtAdded+6