Spaces:
Running
Running
File size: 1,553 Bytes
14f4c95 942bf87 51a3749 3a814dc 51a3749 f0357dd 51a3749 f0357dd 942bf87 51a3749 f0357dd d5efa2c 15020eb 51a3749 14f4c95 d5efa2c f0357dd 51a3749 f0357dd 942bf87 f0357dd 8310453 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
import joblib
import numpy as np
from propy import AAComposition
from sklearn.preprocessing import MinMaxScaler
# Load trained SVM model and scaler (Ensure both files exist in the Space)
model = joblib.load("SVM.joblib")
scaler = MinMaxScaler()
def extract_features(sequence):
"""Calculate AAC, Dipeptide Composition, and normalize features."""
# Calculate Amino Acid Composition (AAC) and convert to array
aac = np.array(list(propy.AAComposition.CalculateAAC(sequence).values()))
# Calculate Dipeptide Composition and convert to array
dipeptide_comp = np.array(list(propy.AAComposition.CalculateAADipeptideComposition(sequence).values()))
# Combine both features (AAC and Dipeptide Composition)
features = np.concatenate((aac, dipeptide_comp))
# Normalize using the pre-trained scaler (Ensure the scaler is loaded correctly)
normalized_features = scaler.transform([features]) # Don't use fit_transform(), only transform()
return normalized_features
def predict(sequence):
"""Predict AMP vs Non-AMP"""
features = extract_features(sequence)
prediction = model.predict(features)[0]
return "AMP" if prediction == 1 else "Non-AMP"
# Create Gradio interface
iface = gr.Interface(
fn=predict,
inputs=gr.Textbox(label="Enter Protein Sequence"),
outputs=gr.Label(label="Prediction"),
title="AMP Classifier",
description="Enter an amino acid sequence to predict whether it's an antimicrobial peptide (AMP) or not."
)
# Launch app
iface.launch(share=True)
|