shobrunjb commited on
Commit
79f910e
·
verified ·
1 Parent(s): f7be72d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import torch
3
- from transformers import BertTokenizer, BertModel
4
  import torch.nn.functional as F
5
 
6
  # Load model and tokenizer from Hugging Face
@@ -25,12 +25,13 @@ class IndoBERTMultiTaskClassifier(torch.nn.Module):
25
 
26
  return logits_task1, logits_task2
27
 
28
- # Load model directly from Hugging Face
29
  model = IndoBERTMultiTaskClassifier(
30
  bert_model_name=model_name,
31
  num_labels_task1=3, # Adjust with your task1 classes
32
  num_labels_task2=3 # Adjust with your task2 classes
33
  )
 
34
  model.eval()
35
 
36
  # Define label mappings
@@ -62,8 +63,8 @@ iface = gr.Interface(
62
  fn=classify,
63
  inputs="text",
64
  outputs=[
65
- gr.outputs.Label(label="Fake Review Detection"),
66
- gr.outputs.Label(label="Sentiment Classification")
67
  ],
68
  title="Multitask IndoBERT: Fake Review & Sentiment Classification",
69
  description="Enter a skincare product review in Indonesian and the model will classify it as fake or trusted, and determine the sentiment.",
 
1
  import gradio as gr
2
  import torch
3
+ from transformers import BertTokenizer
4
  import torch.nn.functional as F
5
 
6
  # Load model and tokenizer from Hugging Face
 
25
 
26
  return logits_task1, logits_task2
27
 
28
+ # Load the model checkpoint into your multitask model class
29
  model = IndoBERTMultiTaskClassifier(
30
  bert_model_name=model_name,
31
  num_labels_task1=3, # Adjust with your task1 classes
32
  num_labels_task2=3 # Adjust with your task2 classes
33
  )
34
+ model.load_state_dict(torch.load("pytorch_model.bin", map_location=torch.device('cpu')))
35
  model.eval()
36
 
37
  # Define label mappings
 
63
  fn=classify,
64
  inputs="text",
65
  outputs=[
66
+ gr.Label(label="Fake Review Detection"),
67
+ gr.Label(label="Sentiment Classification")
68
  ],
69
  title="Multitask IndoBERT: Fake Review & Sentiment Classification",
70
  description="Enter a skincare product review in Indonesian and the model will classify it as fake or trusted, and determine the sentiment.",