Commit
·
3b4763b
1
Parent(s):
5d74a88
Removing embedding choice
Browse files- .gitignore +1 -0
- 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 |
-
|
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 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.")
|