Update app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ class BERT_Arch(nn.Module):
|
|
| 35 |
|
| 36 |
# Load the model and set it to evaluation mode
|
| 37 |
model = BERT_Arch(bert)
|
| 38 |
-
fake_news_model_path = "
|
| 39 |
fake_news_model = torch.load(fake_news_model_path, map_location=torch.device('cpu'))
|
| 40 |
fake_news_model.eval()
|
| 41 |
|
|
@@ -45,26 +45,26 @@ def detect_fake_news(text):
|
|
| 45 |
with torch.no_grad():
|
| 46 |
outputs = fake_news_model(inputs['input_ids'], inputs['attention_mask'])
|
| 47 |
label = torch.argmax(outputs, dim=1).item()
|
| 48 |
-
fake_news_result = "
|
| 49 |
return fake_news_result
|
| 50 |
|
| 51 |
# Function to handle post logic
|
| 52 |
def post_text(text, fake_news_result):
|
| 53 |
-
if fake_news_result == "
|
| 54 |
-
return "Your message contains
|
| 55 |
else:
|
| 56 |
return "The text is safe to post.", text
|
| 57 |
|
| 58 |
# Gradio Interface
|
| 59 |
interface = gr.Blocks()
|
| 60 |
with interface:
|
| 61 |
-
gr.Markdown("##
|
| 62 |
with gr.Row():
|
| 63 |
text_input = gr.Textbox(label="Enter Text", lines=5)
|
| 64 |
with gr.Row():
|
| 65 |
-
detect_fake_button = gr.Button("Detect
|
| 66 |
with gr.Row():
|
| 67 |
-
fake_news_result_box = gr.Textbox(label="
|
| 68 |
with gr.Row():
|
| 69 |
post_button = gr.Button("Post Text")
|
| 70 |
with gr.Row():
|
|
|
|
| 35 |
|
| 36 |
# Load the model and set it to evaluation mode
|
| 37 |
model = BERT_Arch(bert)
|
| 38 |
+
fake_news_model_path = "Hate_Speech_model.pt"
|
| 39 |
fake_news_model = torch.load(fake_news_model_path, map_location=torch.device('cpu'))
|
| 40 |
fake_news_model.eval()
|
| 41 |
|
|
|
|
| 45 |
with torch.no_grad():
|
| 46 |
outputs = fake_news_model(inputs['input_ids'], inputs['attention_mask'])
|
| 47 |
label = torch.argmax(outputs, dim=1).item()
|
| 48 |
+
fake_news_result = "Hate" if label == 1 else "Real"
|
| 49 |
return fake_news_result
|
| 50 |
|
| 51 |
# Function to handle post logic
|
| 52 |
def post_text(text, fake_news_result):
|
| 53 |
+
if fake_news_result == "Hate":
|
| 54 |
+
return "Your message contains Hate Speech and cannot be posted.", ""
|
| 55 |
else:
|
| 56 |
return "The text is safe to post.", text
|
| 57 |
|
| 58 |
# Gradio Interface
|
| 59 |
interface = gr.Blocks()
|
| 60 |
with interface:
|
| 61 |
+
gr.Markdown("## Hate Speech Detection")
|
| 62 |
with gr.Row():
|
| 63 |
text_input = gr.Textbox(label="Enter Text", lines=5)
|
| 64 |
with gr.Row():
|
| 65 |
+
detect_fake_button = gr.Button("Detect Hate Speech")
|
| 66 |
with gr.Row():
|
| 67 |
+
fake_news_result_box = gr.Textbox(label="Hate speech Detection Result", interactive=False)
|
| 68 |
with gr.Row():
|
| 69 |
post_button = gr.Button("Post Text")
|
| 70 |
with gr.Row():
|