naveed-stockmark commited on
Commit
3cf5a8c
1 Parent(s): e1ca1e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -15
app.py CHANGED
@@ -10,8 +10,21 @@ ENTITY_LINKING_PATH = "./linking_df_technical_min.csv"
10
 
11
  st.title("Materials use case search app")
12
 
13
- """Loading entity metadata ..."""
14
- wiki_df = pd.read_csv(WIKIPEDIA_PATH)
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # filter out technical articles
17
  exclude_ids = set(wiki_df[(wiki_df.exclude == True) | (wiki_df.technical == False)].page_id.to_list())
@@ -22,14 +35,22 @@ wiki_df = wiki_df.rename(columns={'title_x': 'en_title'})
22
 
23
  # load kg df
24
 
25
- """Loading Wikidata relations ..."""
26
- wikidata_df = pd.read_csv(WIKIDATA_PATH)
 
 
 
 
27
 
28
  # filter technical wikidata
29
  wikidata_df = wikidata_df[wikidata_df.apply(lambda x: x.source_skpe in include_skpes and x.target_skpe in include_skpes, axis=1)]
30
 
31
- """Loading Wikipedia inference relations ..."""
32
- rebel_infer_df = pd.read_csv(REBEL_INFER_PATH)
 
 
 
 
33
 
34
  # filter technical
35
  rebel_infer_df = rebel_infer_df[rebel_infer_df.apply(lambda x: type(x.source_skpe_id) == str and type(x.target_skpe_id) == str, axis=1)]
@@ -45,16 +66,12 @@ rebel_infer_df = rebel_infer_df[rebel_infer_df.source_skpe != rebel_infer_df.tar
45
 
46
  kg_df = pd.concat([wikidata_df, rebel_infer_df])
47
 
 
 
 
 
48
 
49
- """Loading entity linking dictionary ..."""
50
- linking_df = pd.read_csv(ENTITY_LINKING_PATH)
51
-
52
- # User Input
53
- input_text = st.text_input(
54
- label="Enter the name of a material i.e steel, sand, plastic, etc and press Enter",
55
- value="steel",
56
- key="ent",
57
- )
58
 
59
  # normalise and match
60
  text_norm = normalize_text(input_text)
 
10
 
11
  st.title("Materials use case search app")
12
 
13
+ # User Input
14
+ input_text = st.text_input(
15
+ label="Enter the name of a material i.e steel, sand, plastic, etc and press Enter",
16
+ value="steel",
17
+ key="ent",
18
+ )
19
+
20
+ st.write("preparing data ...")
21
+
22
+ @st.cache_data(persist="disk")
23
+ def get_wiki_df():
24
+ wiki_df = pd.read_csv(WIKIPEDIA_PATH)
25
+ return wiki_df
26
+
27
+ wiki_df = get_wiki_df()
28
 
29
  # filter out technical articles
30
  exclude_ids = set(wiki_df[(wiki_df.exclude == True) | (wiki_df.technical == False)].page_id.to_list())
 
35
 
36
  # load kg df
37
 
38
+ @st.cache_data(persist="disk")
39
+ def get_wikidata_df():
40
+ wikidata_df = pd.read_csv(WIKIDATA_PATH)
41
+ return wikidata_df
42
+
43
+ wikidata_df = get_wikidata_df()
44
 
45
  # filter technical wikidata
46
  wikidata_df = wikidata_df[wikidata_df.apply(lambda x: x.source_skpe in include_skpes and x.target_skpe in include_skpes, axis=1)]
47
 
48
+ @st.cache_data(persist="disk")
49
+ def get_rebel_infer_df():
50
+ rebel_infer_df = pd.read_csv(REBEL_INFER_PATH)
51
+ return rebel_infer_df
52
+
53
+ rebel_infer_df = get_rebel_infer_df()
54
 
55
  # filter technical
56
  rebel_infer_df = rebel_infer_df[rebel_infer_df.apply(lambda x: type(x.source_skpe_id) == str and type(x.target_skpe_id) == str, axis=1)]
 
66
 
67
  kg_df = pd.concat([wikidata_df, rebel_infer_df])
68
 
69
+ @st.cache_data(persist="disk")
70
+ def get_entity_linking_df():
71
+ linking_df = pd.read_csv(ENTITY_LINKING_PATH)
72
+ return linking_df
73
 
74
+ linking_df = get_entity_linking_df()
 
 
 
 
 
 
 
 
75
 
76
  # normalise and match
77
  text_norm = normalize_text(input_text)