Spaces:
Sleeping
Sleeping
add css
Browse filesAdds css functionality
app.py
CHANGED
|
@@ -56,7 +56,7 @@ def predict(text):
|
|
| 56 |
inputs = tokenizer.texts_to_sequences([inputs])
|
| 57 |
print(f"Tokenized text: {inputs}")
|
| 58 |
|
| 59 |
-
inputs = pad_sequences(inputs, maxlen=
|
| 60 |
print(f"Padded text: {inputs}")
|
| 61 |
|
| 62 |
outputs = model.predict(inputs)
|
|
@@ -65,15 +65,64 @@ def predict(text):
|
|
| 65 |
# Interpret the output as a prediction
|
| 66 |
prediction = outputs[0][0]
|
| 67 |
if prediction >= 0.5:
|
| 68 |
-
result = f"
|
| 69 |
else:
|
| 70 |
-
result = f"
|
| 71 |
|
| 72 |
return result
|
| 73 |
except Exception as e:
|
| 74 |
print(f"Error during prediction: {e}")
|
| 75 |
return f"Error during prediction: {e}"
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# Set up the Gradio interface
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
demo.launch()
|
|
|
|
| 56 |
inputs = tokenizer.texts_to_sequences([inputs])
|
| 57 |
print(f"Tokenized text: {inputs}")
|
| 58 |
|
| 59 |
+
inputs = pad_sequences(inputs, maxlen=750, padding='post')
|
| 60 |
print(f"Padded text: {inputs}")
|
| 61 |
|
| 62 |
outputs = model.predict(inputs)
|
|
|
|
| 65 |
# Interpret the output as a prediction
|
| 66 |
prediction = outputs[0][0]
|
| 67 |
if prediction >= 0.5:
|
| 68 |
+
result = f"True = {prediction:.2f}"
|
| 69 |
else:
|
| 70 |
+
result = f"False = {prediction:.2f}"
|
| 71 |
|
| 72 |
return result
|
| 73 |
except Exception as e:
|
| 74 |
print(f"Error during prediction: {e}")
|
| 75 |
return f"Error during prediction: {e}"
|
| 76 |
+
ui_css = """
|
| 77 |
+
#body {
|
| 78 |
+
height: 600px;
|
| 79 |
+
width: 500px;
|
| 80 |
+
}
|
| 81 |
+
#input-box {
|
| 82 |
+
width: 480px;
|
| 83 |
+
border: 2px solid black;
|
| 84 |
+
margin: 8px;
|
| 85 |
+
}
|
| 86 |
+
#output-elems {
|
| 87 |
+
width: 480px;
|
| 88 |
+
border: 2px solid black;
|
| 89 |
+
margin-left: 8px;
|
| 90 |
+
margin-right: 8px;
|
| 91 |
+
padding: 1em;
|
| 92 |
+
}
|
| 93 |
+
#submit-button, #clear-button {
|
| 94 |
+
color: white;
|
| 95 |
+
height: 35px;
|
| 96 |
+
width: 60px;
|
| 97 |
+
margin: 10px;
|
| 98 |
+
border-radius: 5px;
|
| 99 |
+
border: 5px solid black;
|
| 100 |
+
}
|
| 101 |
+
#submit-button {
|
| 102 |
+
background-color: red;
|
| 103 |
+
}
|
| 104 |
+
#clear-button {
|
| 105 |
+
background-color: grey;
|
| 106 |
+
}
|
| 107 |
+
"""
|
| 108 |
# Set up the Gradio interface
|
| 109 |
+
with gr.Blocks(elem_id="body", css=ui_css) as demo:
|
| 110 |
+
|
| 111 |
+
with gr.Row(elem_id="header"):
|
| 112 |
+
gr.Image(value="https://universitysurgical.com/wp-content/uploads/2021/12/hipaa-e1638383751916.png")
|
| 113 |
+
gr.Markdown("Place basic instructions here")
|
| 114 |
+
|
| 115 |
+
with gr.Column(elem_id="interactives"):
|
| 116 |
+
inputs=gr.Textbox(label="Enter Text", elem_id="input-box", lines=5)
|
| 117 |
+
|
| 118 |
+
with gr.Row(elem_id="output-elems"):
|
| 119 |
+
gr.Markdown("This text is a violation: ")
|
| 120 |
+
outputs=gr.Textbox(label="Prediction Result", elem_id="output-box", interactive=False)
|
| 121 |
+
|
| 122 |
+
with gr.Row():
|
| 123 |
+
submit_button = gr.Button("Submit", elem_id="submit-button")
|
| 124 |
+
clear_button = gr.Button("Clear", elem_id="clear-button")
|
| 125 |
+
|
| 126 |
+
submit_button.click(predict, inputs=inputs, outputs=outputs)
|
| 127 |
+
clear_button.click(lambda: ("", ""), inputs=None, outputs=[inputs, outputs])
|
| 128 |
demo.launch()
|