AMP-Classifier / app.py
nonzeroexit's picture
Update app.py
4c53eb3 verified
raw
history blame
1.38 kB
import gradio as gr
import joblib
import numpy as np
import propy
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)
aac = propy.AAComposition.CalculateAAC(sequence)
# Calculate Dipeptide Composition
dipeptide_comp = propy.AAComposition.CalculateAADipeptideComposition(sequence)
# Combine both features (AAC and Dipeptide Composition)
features = np.concatenate((aac, dipeptide_comp))
# Normalize with pre-trained scaler (avoid fitting new data)
normalized_features = scaler.transform([features])
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()