Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -537,7 +537,7 @@ def predict_with_keras(sequence):
|
|
| 537 |
return f"Keras model not available. Input sequence: {sequence[:100]}..."
|
| 538 |
|
| 539 |
if len(sequence) < 6:
|
| 540 |
-
return "
|
| 541 |
|
| 542 |
# Generate k-mers
|
| 543 |
kmers = [sequence[i:i+6] for i in range(len(sequence)-5)]
|
|
@@ -547,9 +547,13 @@ def predict_with_keras(sequence):
|
|
| 547 |
input_arr = np.array([indices])
|
| 548 |
prediction = keras_model.predict(input_arr, verbose=0)[0]
|
| 549 |
|
| 550 |
-
#
|
| 551 |
-
|
| 552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
except Exception as e:
|
| 554 |
logging.error(f"Keras prediction failed: {e}")
|
| 555 |
return f"Keras prediction failed: {str(e)}"
|
|
@@ -627,13 +631,8 @@ def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
|
|
| 627 |
keras_output = ""
|
| 628 |
if processed_sequence and len(processed_sequence) >= 6:
|
| 629 |
keras_prediction = predict_with_keras(processed_sequence)
|
| 630 |
-
#
|
| 631 |
-
|
| 632 |
-
# You might want to add logic here to interpret the prediction scores
|
| 633 |
-
# For now, just show the prediction
|
| 634 |
-
keras_output = f"F gene validation scores: {keras_prediction[:100]}..."
|
| 635 |
-
else:
|
| 636 |
-
keras_output = keras_prediction
|
| 637 |
else:
|
| 638 |
keras_output = "Skipped: sequence too short for F gene validation"
|
| 639 |
|
|
@@ -731,7 +730,6 @@ def run_pipeline(dna_input, similarity_score=95.0, build_ml_tree=False):
|
|
| 731 |
None, None, None, error_msg
|
| 732 |
)
|
| 733 |
|
| 734 |
-
# --- Gradio Interface ---
|
| 735 |
# --- Gradio Interface ---
|
| 736 |
def create_interface():
|
| 737 |
"""Create the Gradio interface with enhanced layout and features"""
|
|
|
|
| 537 |
return f"Keras model not available. Input sequence: {sequence[:100]}..."
|
| 538 |
|
| 539 |
if len(sequence) < 6:
|
| 540 |
+
return "Skipped: sequence too short for F gene validation (minimum 6 nucleotides required)."
|
| 541 |
|
| 542 |
# Generate k-mers
|
| 543 |
kmers = [sequence[i:i+6] for i in range(len(sequence)-5)]
|
|
|
|
| 547 |
input_arr = np.array([indices])
|
| 548 |
prediction = keras_model.predict(input_arr, verbose=0)[0]
|
| 549 |
|
| 550 |
+
# Assume the last value is the F gene probability (adjust index if model outputs differ)
|
| 551 |
+
f_gene_prob = prediction[-1] # Take the probability of the F gene class
|
| 552 |
+
|
| 553 |
+
# Convert to percentage with a buffer (e.g., add 5% to account for minor mismatches)
|
| 554 |
+
percentage = min(100, max(0, int(f_gene_prob * 100 + 5))) # Ensure 0-100% range
|
| 555 |
+
|
| 556 |
+
return f"{percentage}% F gene"
|
| 557 |
except Exception as e:
|
| 558 |
logging.error(f"Keras prediction failed: {e}")
|
| 559 |
return f"Keras prediction failed: {str(e)}"
|
|
|
|
| 631 |
keras_output = ""
|
| 632 |
if processed_sequence and len(processed_sequence) >= 6:
|
| 633 |
keras_prediction = predict_with_keras(processed_sequence)
|
| 634 |
+
# Use the prediction directly as it’s now a percentage
|
| 635 |
+
keras_output = keras_prediction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 636 |
else:
|
| 637 |
keras_output = "Skipped: sequence too short for F gene validation"
|
| 638 |
|
|
|
|
| 730 |
None, None, None, error_msg
|
| 731 |
)
|
| 732 |
|
|
|
|
| 733 |
# --- Gradio Interface ---
|
| 734 |
def create_interface():
|
| 735 |
"""Create the Gradio interface with enhanced layout and features"""
|