Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,26 +15,38 @@ def load_model():
|
|
15 |
model.eval()
|
16 |
|
17 |
return model, tokenizer
|
18 |
-
|
19 |
model, tokenizer = load_model()
|
20 |
|
21 |
st.title("FLAN-T5 Typosquatting Detection")
|
22 |
st.write("Enter a potential typosquatted domain and a target domain to check if one is a variant of the other.")
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
potential_typosquat = st.text_input("Potential Typosquatted Domain", value="lonlonsoft.com")
|
25 |
-
target_domain = st.text_input("
|
26 |
|
|
|
|
|
|
|
|
|
27 |
if st.button("Check Typosquatting"):
|
28 |
if potential_typosquat and target_domain:
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
33 |
outputs = model.generate(input_ids, max_new_tokens=20)
|
34 |
|
|
|
35 |
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
36 |
|
|
|
37 |
st.write("**Prediction:**")
|
38 |
st.write(prediction)
|
39 |
else:
|
40 |
-
st.warning("Please enter both domains to perform the check.")
|
|
|
15 |
model.eval()
|
16 |
|
17 |
return model, tokenizer
|
18 |
+
device='cpu'
|
19 |
model, tokenizer = load_model()
|
20 |
|
21 |
st.title("FLAN-T5 Typosquatting Detection")
|
22 |
st.write("Enter a potential typosquatted domain and a target domain to check if one is a variant of the other.")
|
23 |
|
24 |
+
# Non-editable prompt part
|
25 |
+
prompt_prefix = "Is the first domain a typosquat of the second:"
|
26 |
+
|
27 |
+
# Display the non-editable prompt with input fields for the rest
|
28 |
+
st.markdown("### Prompt")
|
29 |
+
st.text_area("Prompt", prompt_prefix, height=50, disabled=True)
|
30 |
+
|
31 |
+
# User inputs for dynamic part of the prompt
|
32 |
potential_typosquat = st.text_input("Potential Typosquatted Domain", value="lonlonsoft.com")
|
33 |
+
target_domain = st.text_input("Legitimate Domain", value="stiltsoft.net")
|
34 |
|
35 |
+
# Generate prompt by combining fixed and dynamic parts
|
36 |
+
full_prompt = f"{prompt_prefix} {potential_typosquat} {target_domain}"
|
37 |
+
|
38 |
+
# Perform inference when button is clicked
|
39 |
if st.button("Check Typosquatting"):
|
40 |
if potential_typosquat and target_domain:
|
41 |
+
# Encode and generate response
|
42 |
+
input_ids = tokenizer(full_prompt, return_tensors="pt").input_ids.to(device)
|
|
|
|
|
43 |
outputs = model.generate(input_ids, max_new_tokens=20)
|
44 |
|
45 |
+
# Decode the response
|
46 |
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
47 |
|
48 |
+
# Display the result
|
49 |
st.write("**Prediction:**")
|
50 |
st.write(prediction)
|
51 |
else:
|
52 |
+
st.warning("Please enter both domains to perform the check.")
|