File size: 1,328 Bytes
21a6064
3b25244
 
 
 
21a6064
3b25244
 
 
21a6064
3b25244
 
 
 
 
21a6064
3b25244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
39
import streamlit as st
from sentence_transformers import SentenceTransformer, util
import pandas as pd
import numpy as np
from ast import literal_eval

# Load the model
model_name = "./Embedder-typosquat" 
model = SentenceTransformer(model_name)

# Load the domains and embeddings
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)

# Streamlit App
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.")

# User Inputs
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)

# Perform Semantic Search
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]
    
    # Create a DataFrame for the results
    res_df = domains_df.iloc[ids].copy()
    res_df['score'] = scores
    
    # Display the result DataFrame
    st.write("Mined Domains:")
    st.dataframe(res_df)