-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (40 loc) · 1.89 KB
/
Copy pathapp.py
File metadata and controls
50 lines (40 loc) · 1.89 KB
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
46
47
48
49
50
import streamlit as st
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
import tensorflow as tf
from tensorflow.keras.models import Model
from tensorflow.keras.layers import (Input, Conv1D, MaxPooling1D, Bidirectional, LSTM,
Dense, GlobalAveragePooling1D, Attention)
# Assuming your one_hot_encode and pad_sequence functions are defined as before
def one_hot_encode(seq):
mapping = {'A': [1, 0, 0, 0],
'C': [0, 1, 0, 0],
'G': [0, 0, 1, 0],
'T': [0, 0, 0, 1]}
return np.array([mapping[i] for i in seq])
def pad_sequence(encoded_seq, max_len=1000): # Adjust max_len based on your model
padding_needed = max_len - len(encoded_seq)
return np.pad(encoded_seq, ((0, padding_needed), (0, 0)), 'constant')
# Load the model
model_path = "Model/ssr_model_v2.h5" # Update the path to where your model is saved
model = load_model(model_path)
# Define the label encoder classes based on your dataset labels
class_labels = ['di', 'hexa', 'penta', 'tetra', 'tri']
st.title("DNA Sequence Classification")
user_sequence = st.text_area("Enter DNA sequence:", "Type or paste sequence here...")
if st.button("Classify"):
if user_sequence:
# Preprocess the input sequence
encoded_sequence = one_hot_encode(user_sequence.upper())
padded_sequence = pad_sequence(encoded_sequence)
sequence_to_classify = np.expand_dims(padded_sequence, axis=0)
# Predict
prediction = model.predict(sequence_to_classify)
predicted_index = np.argmax(prediction, axis=1)[0]
predicted_label = class_labels[predicted_index]
st.write(f"Predicted Class: {predicted_label}")
else:
st.write("Please enter a valid sequence.")