Rthur2003 commited on
Commit
45def97
·
1 Parent(s): 3f5c3a0

feat: add XAI explanation models for enhanced interpretability in analysis results

Browse files
Files changed (1) hide show
  1. app/routes/analyze.py +43 -0
app/routes/analyze.py CHANGED
@@ -122,6 +122,47 @@ class AudioInfo(BaseModel):
122
  sampleRate: int = 44100
123
  bitrate: int = 128
124
  format: str = "unknown"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
 
127
  class AnalysisResult(BaseModel):
@@ -137,6 +178,8 @@ class AnalysisResult(BaseModel):
137
  features: AnalysisFeatures
138
  audioInfo: AudioInfo
139
  vocalAnalysis: Optional[VocalAnalysis] = None
 
 
140
 
141
 
142
  class AnalyzeResponse(BaseModel):
 
122
  sampleRate: int = 44100
123
  bitrate: int = 128
124
  format: str = "unknown"
125
+ channels: int = 2
126
+
127
+
128
+ class ConfidenceBandModel(BaseModel):
129
+ tier: str
130
+ labelTr: str
131
+ labelEn: str
132
+ lowerBound: float
133
+ upperBound: float
134
+
135
+
136
+ class ModelVoteModel(BaseModel):
137
+ name: str
138
+ probability: float
139
+ vote: str
140
+
141
+
142
+ class FeatureContributionModel(BaseModel):
143
+ name: str
144
+ label: str
145
+ labelEn: str
146
+ category: str
147
+ value: float
148
+ zScore: float
149
+ shapValue: float
150
+ direction: str
151
+ description: str
152
+
153
+
154
+ class XAIExplanation(BaseModel):
155
+ """Rich explainable analysis payload."""
156
+
157
+ probability: float
158
+ threshold: float
159
+ baseProbability: float
160
+ confidenceBand: ConfidenceBandModel
161
+ modelVotes: List[ModelVoteModel] = Field(default_factory=list)
162
+ bestModel: str = "XGBoost"
163
+ topContributions: List[FeatureContributionModel] = Field(default_factory=list)
164
+ allFeatures: Dict[str, FeatureContributionModel] = Field(default_factory=dict)
165
+ featureCount: int = 0
166
 
167
 
168
  class AnalysisResult(BaseModel):
 
178
  features: AnalysisFeatures
179
  audioInfo: AudioInfo
180
  vocalAnalysis: Optional[VocalAnalysis] = None
181
+ xai: Optional[XAIExplanation] = None
182
+ towerScores: Dict[str, float] = Field(default_factory=dict)
183
 
184
 
185
  class AnalyzeResponse(BaseModel):