rande commited on
Commit
0991258
1 Parent(s): 0790bf8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -9
app.py CHANGED
@@ -5,6 +5,31 @@ import os
5
  import pandas as pd
6
  import json
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # Get the absolute path of the script directory
9
  cwd = os.getcwd()
10
 
@@ -39,18 +64,13 @@ def main():
39
  # StreamLit Title
40
  st.title("TagaCare")
41
 
42
- nlp = tl_calamancy_lg.load()
43
-
44
  doc1 = nlp("Pano gamutin ang sakit sa ngipin")
45
 
46
  st.success(doc1)
47
-
48
- for data in patterns_data:
49
- st.write(data)
50
-
51
- for data in responses_data:
52
- st.write(data)
53
-
54
 
55
  if __name__ == "__main__":
56
  main()
 
5
  import pandas as pd
6
  import json
7
 
8
+ nlp = tl_calamancy_lg.load()
9
+
10
+ def get_most_similar_tag(user_query, dataframe):
11
+ # Process user query and existing queries with spaCy
12
+ all_queries = list(dataframe['query']) + [user_query]
13
+ processed_queries = [nlp(query) for query in all_queries]
14
+
15
+ # Get word vectors for each query
16
+ vectors = [query.vector for query in processed_queries]
17
+
18
+ # Calculate cosine similarity
19
+ similarity_matrix = cosine_similarity(vectors, vectors)
20
+
21
+ # Extract similarity scores for the user query
22
+ user_similarity_scores = similarity_matrix[-1, :-1]
23
+
24
+ # Find the index of the tag with the highest similarity score
25
+ most_similar_index = user_similarity_scores.argmax()
26
+
27
+ # Get the most similar tag
28
+ most_similar_tag = dataframe['tag'].iloc[most_similar_index]
29
+
30
+ # Return the most similar tag and its similarity score
31
+ return most_similar_tag, user_similarity_scores[most_similar_index]
32
+
33
  # Get the absolute path of the script directory
34
  cwd = os.getcwd()
35
 
 
64
  # StreamLit Title
65
  st.title("TagaCare")
66
 
 
 
67
  doc1 = nlp("Pano gamutin ang sakit sa ngipin")
68
 
69
  st.success(doc1)
70
+
71
+ returned_tag, returned_score = get_most_similar_tag("Anong lunas sa masakit ang likod")
72
+
73
+ st.success(returned_tag + str(returned_score))
 
 
 
74
 
75
  if __name__ == "__main__":
76
  main()