Valestino commited on
Commit
1119928
·
verified ·
1 Parent(s): 7c886b7

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -10,17 +10,15 @@ Original file is located at
10
  import gradio as gr
11
  import torch
12
  import torch.nn.functional as F
13
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
14
- from safetensors.torch import load_file
15
  import os
16
 
17
  def load_model():
18
- # Load the model architecture
19
  model_name = "indobenchmark/indobert-lite-large-p2"
20
- model = AutoModelForSequenceClassification.from_pretrained(
21
  model_name,
22
  num_labels=3,
23
- # Add these parameters to avoid random initialization warnings
24
  local_files_only=False,
25
  ignore_mismatched_sizes=True
26
  )
@@ -30,7 +28,7 @@ def load_model():
30
  # Option 1: Load from local safetensors file
31
  local_model_path = "model.safetensors"
32
  if os.path.exists(local_model_path):
33
- weights = load_file(local_model_path)
34
  model.load_state_dict(weights)
35
  else:
36
  print("Warning: No local model weights found. Using pre-trained weights.")
@@ -45,7 +43,7 @@ def load_model():
45
  model = load_model()
46
 
47
  # Load the tokenizer
48
- tokenizer = AutoTokenizer.from_pretrained('indobenchmark/indobert-lite-large-p2')
49
 
50
  def predict_stress_with_accuracy(text_input):
51
  if not text_input.strip():
 
10
  import gradio as gr
11
  import torch
12
  import torch.nn.functional as F
13
+ from transformers import BertTokenizer, BertForSequenceClassification
 
14
  import os
15
 
16
  def load_model():
17
+ # Use BertForSequenceClassification instead of AutoModelForSequenceClassification
18
  model_name = "indobenchmark/indobert-lite-large-p2"
19
+ model = BertForSequenceClassification.from_pretrained(
20
  model_name,
21
  num_labels=3,
 
22
  local_files_only=False,
23
  ignore_mismatched_sizes=True
24
  )
 
28
  # Option 1: Load from local safetensors file
29
  local_model_path = "model.safetensors"
30
  if os.path.exists(local_model_path):
31
+ weights = torch.load(local_model_path)
32
  model.load_state_dict(weights)
33
  else:
34
  print("Warning: No local model weights found. Using pre-trained weights.")
 
43
  model = load_model()
44
 
45
  # Load the tokenizer
46
+ tokenizer = BertTokenizer.from_pretrained('indobenchmark/indobert-lite-large-p2')
47
 
48
  def predict_stress_with_accuracy(text_input):
49
  if not text_input.strip():