|
import streamlit as st |
|
from sentence_transformers import SentenceTransformer, util |
|
import pandas as pd |
|
import numpy as np |
|
from ast import literal_eval |
|
|
|
|
|
model_name = "./Embedder-typosquat" |
|
model = SentenceTransformer(model_name) |
|
|
|
|
|
domains_df = pd.read_csv('domains_embs.csv') |
|
domains_df.embedding = domains_df.embedding.apply(literal_eval) |
|
corpus_domains = domains_df.domain.to_list() |
|
corpus_embeddings = np.stack(domains_df.embedding.values) |
|
|
|
|
|
st.title("Mining Potential Legitimate Domains from a Typosquatted Domain") |
|
st.write("Enter a potential typosquatted domain and select the number of top results to retrieve.") |
|
|
|
|
|
domain = st.text_input("Potential Typosquatted Domain") |
|
top_k = st.number_input("Top K Results", min_value=1, max_value=len(corpus_domains), value=5, step=1) |
|
|
|
|
|
if domain: |
|
query_emb = model.encode(domain) |
|
semantic_res = util.semantic_search(query_emb, corpus_embeddings, top_k=top_k)[0] |
|
ids = [r['corpus_id'] for r in semantic_res] |
|
scores = [r['score'] for r in semantic_res] |
|
|
|
|
|
res_df = domains_df.iloc[ids].copy() |
|
res_df['score'] = scores |
|
|
|
|
|
st.write("Mined Domains:") |
|
st.dataframe(res_df) |
|
|