anvilogic-mikehart commited on
Commit
3b4763b
·
1 Parent(s): 5d74a88

Removing embedding choice

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +38 -31
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .venv
app.py CHANGED
@@ -5,34 +5,41 @@ import numpy as np
5
  from ast import literal_eval
6
 
7
 
8
- st.title("Mining Potential Legitimate Domains from a Typosquatted Domain")
9
- model_choice = st.selectbox("Select the embedding model:", ["", "Embedder-typosquat-detect-Canine", "Embedder-typosquat-detect"], index=0)
10
-
11
- if model_choice:
12
- model = SentenceTransformer(f"./{model_choice}")
13
-
14
- domains_df = pd.read_csv(f'./{model_choice}/domains_embs.csv')
15
- domains_df.embedding = domains_df.embedding.apply(literal_eval)
16
- corpus_domains = domains_df.domain.to_list()
17
- corpus_embeddings = np.stack(domains_df.embedding.values).astype(np.float32) # Ensure embeddings are float32
18
-
19
- st.write("Enter a potential typosquatted domain and select the number of top results to retrieve.")
20
-
21
- domain = st.text_input("Potential Typosquatted Domain")
22
- top_k = st.number_input("Top K Results", min_value=1, max_value=50, value=5, step=1)
23
-
24
- if st.button("Search for Legitimate Domains"):
25
- if domain:
26
- # Perform Semantic Search
27
- query_emb = model.encode(domain).astype(np.float32) # Ensure query embedding is also float32
28
- semantic_res = util.semantic_search(query_emb, corpus_embeddings, top_k=top_k)[0]
29
- ids = [r['corpus_id'] for r in semantic_res]
30
- scores = [r['score'] for r in semantic_res]
31
-
32
- res_df = domains_df.loc[ids, ['domain']].copy()
33
- res_df['score'] = scores
34
-
35
- st.write("Mined Domains:")
36
- st.dataframe(res_df)
37
- else:
38
- st.warning("Please enter a domain to perform the search.")
 
 
 
 
 
 
 
 
5
  from ast import literal_eval
6
 
7
 
8
+ model_choice = "Embedder-typosquat-detect-Canine"
9
+
10
+ @st.cache_resource
11
+ def load_model() -> SentenceTransformer:
12
+ print("Loading model")
13
+ return SentenceTransformer(f"./{model_choice}")
14
+
15
+ st.title("Search for the target of typosquat domains")
16
+ st.text("This streamlit demonstrates how you can use our domain embedder to find the targets of typosquatted domains. "
17
+ "Each domain is represented as an vector embedding that can be stored in a vector store for efficient retrieval. ")
18
+
19
+ model = load_model()
20
+
21
+
22
+ domains_df = pd.read_csv(f'./{model_choice}/domains_embs.csv')
23
+ domains_df.embedding = domains_df.embedding.apply(literal_eval)
24
+ corpus_domains = domains_df.domain.to_list()
25
+ corpus_embeddings = np.stack(domains_df.embedding.values).astype(np.float32) # Ensure embeddings are float32
26
+
27
+ st.header("Enter a potential typosquatted domain and select the number of top results to retrieve. ")
28
+ domain = st.text_input("Potential Typosquatted Domain")
29
+ top_k = st.number_input("Top K Results", min_value=1, max_value=50, value=5, step=1)
30
+
31
+ if st.button("Search for Legitimate Domains"):
32
+ if domain:
33
+ # Perform Semantic Search
34
+ query_emb = model.encode(domain).astype(np.float32) # Ensure query embedding is also float32
35
+ semantic_res = util.semantic_search(query_emb, corpus_embeddings, top_k=top_k)[0]
36
+ ids = [r['corpus_id'] for r in semantic_res]
37
+ scores = [r['score'] for r in semantic_res]
38
+
39
+ res_df = domains_df.loc[ids, ['domain']].copy()
40
+ res_df['score'] = scores
41
+
42
+ st.write("Mined Domains:")
43
+ st.dataframe(res_df)
44
+ else:
45
+ st.warning("Please enter a domain to perform the search.")