Spaces:
Runtime error
Runtime error
Arpan Chatterjee
commited on
Commit
·
6c94492
1
Parent(s):
05d49b2
updated app.py
Browse files
app.py
CHANGED
@@ -4,34 +4,56 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
4 |
import torch
|
5 |
import torch.nn.functional as F
|
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 |
x = st.slider('Select a value')
|
35 |
st.write(x, 'squared is', x * x)
|
36 |
|
37 |
-
'''
|
|
|
|
|
|
|
|
4 |
import torch
|
5 |
import torch.nn.functional as F
|
6 |
|
7 |
+
@st.cache
|
8 |
+
def predictScore():
|
9 |
+
model_dir = 'model-patent-score'
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
11 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_dir)
|
12 |
+
|
13 |
+
abstract = "The present invention relates to passive optical network (PON), and in particular, to an optical network terminal (ONT) in the PON system. In one embodiment, the optical network terminal includes a first interface coupled to a communications network, a second interface coupled to a network client and a processor including a memory coupled to the first interface and to the second interface, wherein the processor is capable of converting optical signals to electric signals, such that the network client can access the communications network."
|
14 |
+
#abstract = "A shoe midsole is composed of a base plate (1), a cover (2), a plurality of blades (3), and liquid (4). The blades (3) are formed in such a manner as to rise within a first region (11) of the base plate (1). The blades (3) are each composed of a plurality of flat-shaped blade elements (32, 33) separated each other by slits (31), and are tilted toward the toe side or the heel side. The flat-shaped blade elements (32, 33) are disposed in such a manner as to be divergent toward the toe side or the heel side. The base plate (1) and the cover (2) are joined together, thereby forming a closed space (5), and the liquid (4) is sealed in the closed space."
|
15 |
+
inputs = tokenizer.encode_plus(abstract, max_length=512, padding='max_length', truncation=True, return_tensors='pt')
|
16 |
+
|
17 |
+
# Get the model prediction
|
18 |
+
outputs = model(inputs['input_ids'], attention_mask=inputs['attention_mask'])
|
19 |
+
scores = torch.softmax(outputs.logits, dim=1)[0]
|
20 |
+
|
21 |
+
|
22 |
+
probs = F.softmax(scores, dim=0)
|
23 |
+
# Print the scores
|
24 |
+
accept_prob = probs[1].item()
|
25 |
+
print(accept_prob)
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
def main():
|
30 |
+
df = pd.read_pickle("my_dataframe.pkl")
|
31 |
+
abstract_list = df['abstract'].tolist()
|
32 |
+
claims_list = df['claims'].tolist()
|
33 |
+
title_list = df['title'].tolist()
|
34 |
+
pnumber_list = df['patent_number'].tolist()
|
35 |
+
|
36 |
+
display_list = [f"{a}-{b}" for a, b in zip(pnumber_list, title_list)]
|
37 |
+
|
38 |
+
# Prepopulate the drop-down menu with the default value 'Option 2'
|
39 |
+
default_option = display_list[0]
|
40 |
+
|
41 |
+
# Create the drop-down menu with prepopulated default value
|
42 |
+
selected_option = st.selectbox('Select a patent number which is displayed along with its title', display_list, index=display_list.index(default_option))
|
43 |
+
st.write(selected_option)
|
44 |
+
pnumber = selected_option.split("-")[0]
|
45 |
+
print(pnumber)
|
46 |
+
pclaims = df.loc[df['patent_number'] == str(pnumber), 'claims'].iloc[0]
|
47 |
+
pabstract = df.loc[df['patent_number'] == str(pnumber), 'abstract'].iloc[0]
|
48 |
+
print(pclaims)
|
49 |
+
print(pabstract)
|
50 |
+
st.write(pclaims)
|
51 |
+
st.write(pabstract)
|
52 |
'''
|
53 |
x = st.slider('Select a value')
|
54 |
st.write(x, 'squared is', x * x)
|
55 |
|
56 |
+
'''
|
57 |
+
|
58 |
+
if __name__ == '__main__':
|
59 |
+
main()
|