Spaces:
Running
Running
checks input
Browse files- .gitignore +4 -0
- app.py +22 -5
.gitignore
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# git ignore all the csvs they are too big
|
2 |
+
models/
|
3 |
+
|
4 |
+
__pycache__/
|
app.py
CHANGED
@@ -1,18 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
3 |
import numpy as np
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
outputs = [input+'\t'+str(np.random.randint(0,100, size=1)[0]) for input in inputs]
|
8 |
return "\n".join(outputs)
|
9 |
|
10 |
demo = gr.Interface(
|
11 |
-
fn=
|
12 |
inputs=[
|
13 |
"text",
|
14 |
"text",
|
15 |
-
gr.Radio(["bert", "
|
16 |
"number",
|
17 |
gr.Radio(["Binder", "McRae", "Buchanan"]),
|
18 |
],
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import lightning
|
4 |
+
from minicons import cwe
|
5 |
+
import pandas as pd
|
6 |
import numpy as np
|
7 |
|
8 |
+
from model import FeatureNormPredictor
|
9 |
+
|
10 |
+
import sys
|
11 |
+
sys.path.insert(0, '/home/jjr4354/semantic-features')
|
12 |
+
|
13 |
+
def predict (word, sentence, lm_name, layer, norm):
|
14 |
+
if word not in sentence: return "invalid input: word not in sentence"
|
15 |
+
model_name = lm_name + str(layer) + '_to_' + norm
|
16 |
+
lm = cwe.CWE('bert-base-uncased')
|
17 |
+
if layer not in range (lm.layers): return "invalid input: layer not in lm"
|
18 |
+
model = FeatureNormPredictor.load_from_checkpoint(
|
19 |
+
checkpoint_path=model_name+'.ckpt',
|
20 |
+
map_location=None
|
21 |
+
)
|
22 |
+
model.eval()
|
23 |
+
inputs = [word, sentence, lm_name, str(layer), norm]
|
24 |
outputs = [input+'\t'+str(np.random.randint(0,100, size=1)[0]) for input in inputs]
|
25 |
return "\n".join(outputs)
|
26 |
|
27 |
demo = gr.Interface(
|
28 |
+
fn=predict,
|
29 |
inputs=[
|
30 |
"text",
|
31 |
"text",
|
32 |
+
gr.Radio(["bert", "roberta", "electra"]),
|
33 |
"number",
|
34 |
gr.Radio(["Binder", "McRae", "Buchanan"]),
|
35 |
],
|