nonzeroexit commited on
Commit
51a3749
·
verified ·
1 Parent(s): 14f4c95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -7
app.py CHANGED
@@ -1,13 +1,42 @@
1
  import gradio as gr
2
  import joblib
 
 
 
 
 
 
 
 
 
3
 
4
- # Load your trained model
5
- model = joblib.load("SVM.joblib") # Ensure this file is in the correct directory
 
6
 
7
- def predict(sequence):
8
- prediction = model.predict([len(sequence)]) # Adjust based on your features
9
- return "AMP" if prediction[0] else "Non-AMP"
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- iface = gr.Interface(fn=predict, inputs="text", outputs="text")
 
 
 
 
 
 
 
12
 
13
- iface.launch()
 
1
  import gradio as gr
2
  import joblib
3
+ from fastapi import FastAPI
4
+ import joblib
5
+ import numpy as np
6
+ from pydantic import BaseModel
7
+ import propy
8
+ from sklearn.preprocessing import MinMaxScaler
9
+
10
+ # Load trained SVM model
11
+ model = joblib.load("SVM.joblib")
12
 
13
+ # Define request model
14
+ class SequenceInput(BaseModel):
15
+ sequence: str
16
 
17
+ def extract_features(sequence):
18
+ """Calculate AAC, Dipeptide Composition and normalize features."""
19
+ # Calculate Amino Acid Composition (AAC)
20
+ aac = propy.AAComposition.CalculateAAC(sequence)
21
+
22
+ # Calculate Dipeptide Composition
23
+ dipeptide_comp = propy.AAComposition.CalculateAADipeptideComposition(sequence)
24
+
25
+ # Combine both features (AAC and Dipeptide Composition)
26
+ features = np.concatenate((aac, dipeptide_comp))
27
+
28
+ # Min-Max Normalization
29
+ scaler = MinMaxScaler()
30
+ normalized_features = scaler.fit_transform(features.reshape(-1, 1)).flatten()
31
+
32
+ return normalized_features
33
 
34
+ @app.post("/predict/")
35
+ def predict(sequence_input: SequenceInput):
36
+ """Predict AMP vs Non-AMP"""
37
+ sequence = sequence_input.sequence
38
+ features = extract_features(sequence)
39
+ prediction = model.predict([features])[0]
40
+
41
+ return {"sequence": sequence, "prediction": "AMP" if prediction == 1 else "Non-AMP"}
42