Pranjal-psytech commited on
Commit
36358e5
1 Parent(s): 9c7bd1d
Files changed (3) hide show
  1. app.py +37 -2
  2. corona_pred.pkl +3 -0
  3. countVectTrain.pkl +3 -0
app.py CHANGED
@@ -1,7 +1,42 @@
1
  import gradio as gr
 
 
 
 
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import numpy as np
3
+ import pandas as pd
4
+ from sklearn.feature_extraction.text import CountVectorizer
5
+ from sklearn.naive_bayes import MultinomialNB
6
+ import pickle
7
+ import sys
8
 
9
  def greet(name):
10
  return "Hello " + name + "!!"
11
 
12
+ # load the CountVectorizer from disk
13
+ cv = pickle.load(open('countVectTrain.pkl', 'rb'))
14
+
15
+ # load the model from disk
16
+ filename = 'corona_pred.pkl'
17
+ model = pickle.load(open(filename, 'rb'))
18
+
19
+ # function to convert sequence string into k-mer words, default size = 6 (hexamer words)
20
+ kmer_size = 6
21
+ def getKmers(sequence, size=kmer_size):
22
+ return [sequence[x:x+size].lower() for x in range(len(sequence) - size + 1)]
23
+
24
+ # define the Gradio interface
25
+ def classify_sequence(sequence):
26
+ # convert the input sequence into k-mer words
27
+ words = getKmers(sequence)
28
+ # convert the k-mer words into a list of space-separated strings
29
+ text = ' '.join(words)
30
+ # vectorize the text using Count Vectorization
31
+ X = cv.transform([text])
32
+ # make predictions using the pre-trained model
33
+ pred_label = model.predict(X)[0]
34
+ pred_prob_percentage = model.predict_proba(X).max()*100
35
+ # return the predicted class and probability
36
+ return {'predicted_class': pred_label, 'probability': pred_prob_percentage}
37
+
38
+ iface = gr.Interface(fn=classify_sequence, inputs="text", outputs=["text"],
39
+ title="Coronavirus Sequence Classifier",
40
+ description="Enter a coronavirus sequence to predict its class and probability.")
41
+
42
+ iface.launch()
corona_pred.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:55025601de7a3c95b6b902e14284cc6b89464c6d847f764a7941a430af3823f2
3
+ size 11555492
countVectTrain.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2af80dee2648aa8c62746a1d574757b666e185e946701700bac71852671b3968
3
+ size 6189395