Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -195,21 +195,37 @@ def predict(file_obj):
|
|
195 |
)
|
196 |
explanation.expected_value = 0.5 # Start from neutral prediction
|
197 |
|
198 |
-
#
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
)
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
# Calculate final probabilities
|
215 |
with torch.no_grad():
|
|
|
195 |
)
|
196 |
explanation.expected_value = 0.5 # Start from neutral prediction
|
197 |
|
198 |
+
# Calculate step-by-step probabilities
|
199 |
+
step_probs = []
|
200 |
+
current_prob = 0.5 # Start at neutral
|
201 |
+
step_probs.append({"step": "Start", "probability": current_prob, "kmer": "Initial", "change": 0})
|
202 |
+
|
203 |
+
# Process each k-mer contribution
|
204 |
+
for i, kmer in enumerate(important_kmers, 1):
|
205 |
+
change = kmer['importance']
|
206 |
+
current_prob += change
|
207 |
+
step_probs.append({
|
208 |
+
"step": str(i),
|
209 |
+
"probability": current_prob,
|
210 |
+
"kmer": kmer['kmer'],
|
211 |
+
"change": change
|
212 |
+
})
|
213 |
+
|
214 |
+
# Add final "Others" contribution
|
215 |
+
current_prob += others_sum
|
216 |
+
step_probs.append({
|
217 |
+
"step": "Others",
|
218 |
+
"probability": current_prob,
|
219 |
+
"kmer": "Others",
|
220 |
+
"change": others_sum
|
221 |
+
})
|
222 |
+
|
223 |
+
# Convert to JSON for React
|
224 |
+
steps_json = json.dumps(step_probs, indent=2)
|
225 |
+
print(f"Steps data: {steps_json}") # For debugging
|
226 |
+
|
227 |
+
# Create visualization component
|
228 |
+
plot_image = None # We'll use the React component instead
|
229 |
|
230 |
# Calculate final probabilities
|
231 |
with torch.no_grad():
|