peterkros commited on
Commit
1d4525b
·
1 Parent(s): 79860af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -19
app.py CHANGED
@@ -1,22 +1,15 @@
1
  import gradio as gr
2
- from transformers import BertConfig, BertForSequenceClassification, AutoTokenizer
3
- from safetensors import safe_open
4
  import torch
 
5
 
6
- config_path = "peterkros/cofogv1-bert/modelbert2/config.json"
7
- config = BertConfig.from_json_file(config_path)
8
- model = BertForSequenceClassification(config)
9
-
10
-
11
- model_path = "modelbert2"
12
- model = BertForSequenceClassification.from_pretrained(model_path)
13
- tokenizer = AutoTokenizer.from_pretrained(model_path)
14
-
15
- tokenizer = AutoTokenizer.from_pretrained("peterkros/cofogv1-bert/modelbert2/")
16
 
17
  # Load the label encoder
18
- import pickle
19
- with open('peterkros/cofogv1-bert/label_encoder.pkl', 'rb') as file:
20
  label_encoder = pickle.load(file)
21
 
22
  def predict(text):
@@ -28,18 +21,17 @@ def predict(text):
28
  predicted_label = label_encoder.inverse_transform([predicted_class])[0]
29
  return predicted_label
30
 
31
-
32
  # Define the markdown text with bullet points
33
  markdown_text = """
34
- - Trainied with ~1500 rows of data on bert-base-uncased 110M, English
35
- - Input one budget line per time.
36
  - Accuracy of the model is ~72%.
37
  """
38
 
39
  # Define the interface
40
  iface = gr.Interface(
41
  fn=predict,
42
- inputs=gr.inputs.Textbox(lines=1, placeholder="Enter Budget line here..."),
43
  outputs="text",
44
  title="COFOG Level 1 Classification",
45
  description=markdown_text # Add the markdown text to the description
@@ -47,4 +39,4 @@ iface = gr.Interface(
47
 
48
  # Run the interface
49
  if __name__ == "__main__":
50
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
 
3
  import torch
4
+ import pickle
5
 
6
+ # Load the model and tokenizer from Hugging Face Hub
7
+ model_name = "peterkros/cofogv1-bert/modelbert2"
8
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
 
 
 
 
 
 
10
 
11
  # Load the label encoder
12
+ with open('label_encoder.pkl', 'rb') as file:
 
13
  label_encoder = pickle.load(file)
14
 
15
  def predict(text):
 
21
  predicted_label = label_encoder.inverse_transform([predicted_class])[0]
22
  return predicted_label
23
 
 
24
  # Define the markdown text with bullet points
25
  markdown_text = """
26
+ - Trained with ~1500 rows of data on bert-base-uncased, 110M, English.
27
+ - Input one budget line per time.
28
  - Accuracy of the model is ~72%.
29
  """
30
 
31
  # Define the interface
32
  iface = gr.Interface(
33
  fn=predict,
34
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Enter Budget line here..."),
35
  outputs="text",
36
  title="COFOG Level 1 Classification",
37
  description=markdown_text # Add the markdown text to the description
 
39
 
40
  # Run the interface
41
  if __name__ == "__main__":
42
+ iface.launch()