Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,30 @@ from huggingface_hub import InferenceClient
|
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
-
client = InferenceClient("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
|
10 |
def respond(
|
@@ -15,6 +38,9 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
|
|
|
|
|
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
for val in history:
|
@@ -23,21 +49,12 @@ def respond(
|
|
23 |
if val[1]:
|
24 |
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
response =
|
29 |
|
30 |
-
for
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
|
42 |
"""
|
43 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
@@ -45,7 +62,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
-
gr.Textbox(value="You are a
|
49 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
50 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
51 |
gr.Slider(
|
@@ -60,4 +77,4 @@ demo = gr.ChatInterface(
|
|
60 |
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
|
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
+
client = InferenceClient("bert-base-uncased") # Replace with a relevant model for classification or detection
|
8 |
+
|
9 |
+
def detect_passwords(text, threshold=0.9):
|
10 |
+
"""
|
11 |
+
Simulates BERT model usage to detect possible passwords.
|
12 |
+
:param text: Input text containing potential passwords.
|
13 |
+
:param threshold: Confidence score above which a pattern is flagged.
|
14 |
+
:return: Flagged patterns and their confidence scores.
|
15 |
+
"""
|
16 |
+
# Simulated model output (replace with actual BERT inference if supported)
|
17 |
+
tokens = text.split() # Tokenize the input text (basic example)
|
18 |
+
flagged_items = []
|
19 |
+
for token in tokens:
|
20 |
+
# Simulate a condition where tokens matching a simple regex-like pattern are flagged
|
21 |
+
if len(token) > 6 and any(c.isdigit() for c in token) and any(c.isalpha() for c in token):
|
22 |
+
# Simulate confidence score
|
23 |
+
confidence_score = 0.95 # Example confidence for demo purposes
|
24 |
+
if confidence_score > threshold:
|
25 |
+
flagged_items.append((token, confidence_score))
|
26 |
+
|
27 |
+
if not flagged_items:
|
28 |
+
return "No passwords detected."
|
29 |
+
else:
|
30 |
+
return f"Potential passwords detected: {flagged_items}"
|
31 |
|
32 |
|
33 |
def respond(
|
|
|
38 |
temperature,
|
39 |
top_p,
|
40 |
):
|
41 |
+
"""
|
42 |
+
Processes the user's message and history, integrates the password sniffer functionality.
|
43 |
+
"""
|
44 |
messages = [{"role": "system", "content": system_message}]
|
45 |
|
46 |
for val in history:
|
|
|
49 |
if val[1]:
|
50 |
messages.append({"role": "assistant", "content": val[1]})
|
51 |
|
52 |
+
# Simulate BERT-driven password detection for the user's message
|
53 |
+
detected_passwords = detect_passwords(message)
|
54 |
+
response = detected_passwords
|
55 |
|
56 |
+
return response # Outputs directly for demo purposes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
|
|
|
|
58 |
|
59 |
"""
|
60 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
62 |
demo = gr.ChatInterface(
|
63 |
respond,
|
64 |
additional_inputs=[
|
65 |
+
gr.Textbox(value="You are a password detection chatbot.", label="System message"),
|
66 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
67 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
68 |
gr.Slider(
|
|
|
77 |
|
78 |
|
79 |
if __name__ == "__main__":
|
80 |
+
demo.launch()
|