Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import gc
|
4 |
+
|
5 |
+
import numpy as np
|
6 |
+
import pandas as pd
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import seaborn as sns
|
9 |
+
|
10 |
+
from collections import Counter
|
11 |
+
from prettytable import PrettyTable
|
12 |
+
from IPython.display import Image
|
13 |
+
|
14 |
+
from sklearn.preprocessing import LabelEncoder
|
15 |
+
|
16 |
+
from keras.models import Model
|
17 |
+
from keras.regularizers import l2
|
18 |
+
from keras.constraints import max_norm
|
19 |
+
from keras.utils import to_categorical
|
20 |
+
from keras.preprocessing.text import Tokenizer
|
21 |
+
from keras.utils import pad_sequences
|
22 |
+
from keras.callbacks import EarlyStopping
|
23 |
+
from keras.layers import Input, Dense, Dropout, Flatten, Activation
|
24 |
+
from keras.layers import Conv1D, Add, MaxPooling1D, BatchNormalization
|
25 |
+
from keras.layers import Embedding, Bidirectional, LSTM, CuDNNLSTM, GlobalMaxPooling1D
|
26 |
+
|
27 |
+
import tensorflow as tf
|
28 |
+
|
29 |
+
|
30 |
+
def residual_block(data, filters, d_rate):
|
31 |
+
"""
|
32 |
+
_data: input
|
33 |
+
_filters: convolution filters
|
34 |
+
_d_rate: dilation rate
|
35 |
+
"""
|
36 |
+
|
37 |
+
shortcut = data
|
38 |
+
|
39 |
+
bn1 = BatchNormalization()(data)
|
40 |
+
act1 = Activation('relu')(bn1)
|
41 |
+
conv1 = Conv1D(filters, 1, dilation_rate=d_rate, padding='same', kernel_regularizer=l2(0.001))(act1)
|
42 |
+
|
43 |
+
#bottleneck convolution
|
44 |
+
bn2 = BatchNormalization()(conv1)
|
45 |
+
act2 = Activation('relu')(bn2)
|
46 |
+
conv2 = Conv1D(filters, 3, padding='same', kernel_regularizer=l2(0.001))(act2)
|
47 |
+
|
48 |
+
#skip connection
|
49 |
+
x = Add()([conv2, shortcut])
|
50 |
+
|
51 |
+
return x
|
52 |
+
|
53 |
+
def get_model():
|
54 |
+
# model
|
55 |
+
x_input = Input(shape=(100, 21))
|
56 |
+
|
57 |
+
#initial conv
|
58 |
+
conv = Conv1D(128, 1, padding='same')(x_input)
|
59 |
+
|
60 |
+
# per-residue representation
|
61 |
+
res1 = residual_block(conv, 128, 2)
|
62 |
+
res2 = residual_block(res1, 128, 3)
|
63 |
+
|
64 |
+
x = MaxPooling1D(3)(res2)
|
65 |
+
x = Dropout(0.5)(x)
|
66 |
+
|
67 |
+
# softmax classifier
|
68 |
+
x = Flatten()(x)
|
69 |
+
x_output = Dense(1000, activation='softmax', kernel_regularizer=l2(0.0001))(x)
|
70 |
+
|
71 |
+
model2 = Model(inputs=x_input, outputs=x_output)
|
72 |
+
model2.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
|
73 |
+
model2.load_weights('model2.h5')
|
74 |
+
|
75 |
+
return model2
|
76 |
+
|
77 |
+
|
78 |
+
def greet(name):
|
79 |
+
get_model()
|
80 |
+
return "Hello " + name + "!!"
|
81 |
+
|
82 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
83 |
+
iface.launch()
|