Nomi78600 commited on
Commit
6de7857
·
1 Parent(s): 6904b77
Files changed (4) hide show
  1. .gitignore +5 -1
  2. app.py +14 -7
  3. model/config.json +18 -18
  4. requirements.txt +2 -1
.gitignore CHANGED
@@ -66,4 +66,8 @@ venv.bak/
66
 
67
  # IDEs
68
  .idea/
69
- .vscode/
 
 
 
 
 
66
 
67
  # IDEs
68
  .idea/
69
+ .vscode/
70
+
71
+ # Custom
72
+ model/
73
+ upload_model.py
app.py CHANGED
@@ -5,23 +5,30 @@ import torch
5
  import numpy as np
6
 
7
  # --- CONFIGURATION ---
8
- MODEL_DIR = "./model"
9
  st.set_page_config(page_title="NER with BERT", page_icon="🤖", layout="wide")
10
 
11
  # --- MODEL LOADING ---
12
  @st.cache_resource
13
- def load_model_and_tokenizer(model_path):
14
- """Load the fine-tuned model and tokenizer from a local directory."""
15
  try:
16
- tokenizer = AutoTokenizer.from_pretrained(model_path)
17
- model = AutoModelForTokenClassification.from_pretrained(model_path)
18
  return tokenizer, model
 
 
 
19
  except Exception as e:
20
- st.error(f"Error loading model: {e}")
21
  return None, None
22
 
23
- tokenizer, model = load_model_and_tokenizer(MODEL_DIR)
 
 
 
24
  if model is None:
 
25
  st.stop()
26
 
27
  # --- NER VISUALIZATION ---
 
5
  import numpy as np
6
 
7
  # --- CONFIGURATION ---
8
+ MODEL_REPO_ID = "Nomi78600/bert-ner-squad"
9
  st.set_page_config(page_title="NER with BERT", page_icon="🤖", layout="wide")
10
 
11
  # --- MODEL LOADING ---
12
  @st.cache_resource
13
+ def load_model_and_tokenizer(repo_id):
14
+ """Load the fine-tuned model and tokenizer from the Hugging Face Hub."""
15
  try:
16
+ tokenizer = AutoTokenizer.from_pretrained(repo_id)
17
+ model = AutoModelForTokenClassification.from_pretrained(repo_id)
18
  return tokenizer, model
19
+ except OSError:
20
+ st.error(f"Error loading model: Could not find repository '{repo_id}' on the Hugging Face Hub. Please check the name.")
21
+ return None, None
22
  except Exception as e:
23
+ st.error(f"An unexpected error occurred while loading the model: {e}")
24
  return None, None
25
 
26
+ # Load the model from the Hub
27
+ with st.spinner(f"Loading model '{MODEL_REPO_ID}' from Hugging Face Hub..."):
28
+ tokenizer, model = load_model_and_tokenizer(MODEL_REPO_ID)
29
+
30
  if model is None:
31
+ st.error("Application failed to load the model. Please check the logs.")
32
  st.stop()
33
 
34
  # --- NER VISUALIZATION ---
model/config.json CHANGED
@@ -9,28 +9,28 @@
9
  "hidden_dropout_prob": 0.1,
10
  "hidden_size": 768,
11
  "id2label": {
12
- "0": "LABEL_0",
13
- "1": "LABEL_1",
14
- "2": "LABEL_2",
15
- "3": "LABEL_3",
16
- "4": "LABEL_4",
17
- "5": "LABEL_5",
18
- "6": "LABEL_6",
19
- "7": "LABEL_7",
20
- "8": "LABEL_8"
21
  },
22
  "initializer_range": 0.02,
23
  "intermediate_size": 3072,
24
  "label2id": {
25
- "LABEL_0": 0,
26
- "LABEL_1": 1,
27
- "LABEL_2": 2,
28
- "LABEL_3": 3,
29
- "LABEL_4": 4,
30
- "LABEL_5": 5,
31
- "LABEL_6": 6,
32
- "LABEL_7": 7,
33
- "LABEL_8": 8
34
  },
35
  "layer_norm_eps": 1e-12,
36
  "max_position_embeddings": 512,
 
9
  "hidden_dropout_prob": 0.1,
10
  "hidden_size": 768,
11
  "id2label": {
12
+ "0": "O",
13
+ "1": "B-PER",
14
+ "2": "I-PER",
15
+ "3": "B-ORG",
16
+ "4": "I-ORG",
17
+ "5": "B-LOC",
18
+ "6": "I-LOC",
19
+ "7": "B-MISC",
20
+ "8": "I-MISC"
21
  },
22
  "initializer_range": 0.02,
23
  "intermediate_size": 3072,
24
  "label2id": {
25
+ "O": 0,
26
+ "B-PER": 1,
27
+ "I-PER": 2,
28
+ "B-ORG": 3,
29
+ "I-ORG": 4,
30
+ "B-LOC": 5,
31
+ "I-LOC": 6,
32
+ "B-MISC": 7,
33
+ "I-MISC": 8
34
  },
35
  "layer_norm_eps": 1e-12,
36
  "max_position_embeddings": 512,
requirements.txt CHANGED
@@ -4,4 +4,5 @@ streamlit
4
  datasets
5
  seqeval
6
  numpy
7
- scipy
 
 
4
  datasets
5
  seqeval
6
  numpy
7
+ scipy
8
+ huggingface-hub