Desalegnn commited on
Commit
c0bc124
Β·
verified Β·
1 Parent(s): ebfd144

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
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 = "Fake_model.pt"
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 = "Fake" if label == 1 else "Not Fake"
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 == "Fake":
54
- return "Your message contains Fake News 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("## Fake News 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 Fake News")
66
  with gr.Row():
67
- fake_news_result_box = gr.Textbox(label="Fake News Detection Result", interactive=False)
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():