Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdded history handling. Set a hard upper-limit on history. Handled inputs properly. now, it should work.
app.py
CHANGED
@@ -12,33 +12,6 @@ import gradio as gr
|
|
12 |
|
13 |
set_random_seed(65536)
|
14 |
|
15 |
-
|
16 |
-
def respond(
|
17 |
-
message,
|
18 |
-
message1,
|
19 |
-
message2
|
20 |
-
):
|
21 |
-
print(message)
|
22 |
-
print(message1)
|
23 |
-
print(message2)
|
24 |
-
return is_malicious_sql(message, 0.5)
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
"""
|
29 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
30 |
-
"""
|
31 |
-
demo = gr.ChatInterface(
|
32 |
-
respond,
|
33 |
-
additional_inputs=[
|
34 |
-
gr.Slider(minimum=0.01, maximum=0.99, value=0.75, step=0.01, label="Detection Probability Threshold "),
|
35 |
-
],
|
36 |
-
)
|
37 |
-
|
38 |
-
|
39 |
-
if __name__ == "__main__":
|
40 |
-
demo.launch()
|
41 |
-
|
42 |
pandarallel.initialize(use_memory_fs=True, nb_workers=cpu_count())
|
43 |
model = load_model('./sqid.keras')
|
44 |
|
@@ -125,3 +98,35 @@ def is_malicious_sql(sql, threshold):
|
|
125 |
if preds > float(threshold):
|
126 |
return 'Malicious'
|
127 |
return 'Safe'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
set_random_seed(65536)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
pandarallel.initialize(use_memory_fs=True, nb_workers=cpu_count())
|
16 |
model = load_model('./sqid.keras')
|
17 |
|
|
|
98 |
if preds > float(threshold):
|
99 |
return 'Malicious'
|
100 |
return 'Safe'
|
101 |
+
|
102 |
+
|
103 |
+
def respond(
|
104 |
+
message,
|
105 |
+
history,
|
106 |
+
threshold
|
107 |
+
):
|
108 |
+
if len(history) > 5:
|
109 |
+
history = history[1:]
|
110 |
+
for val in history:
|
111 |
+
if val[0].lower().strip() == message.lower().strip():
|
112 |
+
return val[1]
|
113 |
+
|
114 |
+
val = (message.lower().strip(), is_malicious_sql(message, threshold))
|
115 |
+
history.append(val)
|
116 |
+
return val[1]
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
"""
|
121 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
122 |
+
"""
|
123 |
+
demo = gr.ChatInterface(
|
124 |
+
respond,
|
125 |
+
additional_inputs=[
|
126 |
+
gr.Slider(minimum=0.01, maximum=0.99, value=0.75, step=0.01, label="Detection Probability Threshold "),
|
127 |
+
],
|
128 |
+
)
|
129 |
+
|
130 |
+
|
131 |
+
if __name__ == "__main__":
|
132 |
+
demo.launch()
|