straightline777 commited on
Commit
e16ff1d
·
verified ·
1 Parent(s): 5b1bf43

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -25,19 +25,44 @@ def analyze_sentiment(text):
25
  confidence = f"{predictions[0]['score'] * 100:.2f}%"
26
  return f"Predicted Label: {predicted_label}\nConfidence: {confidence}"
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def analyze_ner(text):
29
  predictions = clf_ner(text)
30
  print(predictions) # Debugging statement to see the structure of the output
31
-
32
- # Create label mapping from id2label
33
  keys = []
34
  values = []
35
 
 
 
 
 
36
 
 
37
  results = []
38
  for pred in predictions:
39
  result = f"""Word: {pred['word']}
40
- Predicted Tag: {label_list[pred['entity']]}
41
  Confidence Probability: {pred['score']}\n"""
42
  results.append(result)
43
 
 
25
  confidence = f"{predictions[0]['score'] * 100:.2f}%"
26
  return f"Predicted Label: {predicted_label}\nConfidence: {confidence}"
27
 
28
+ LABEL = ['O',
29
+ 'B-storage',
30
+ 'I-storage',
31
+ 'B-performance',
32
+ 'I-performance',
33
+ 'B-battery',
34
+ 'I-battery',
35
+ 'B-camera',
36
+ 'I-camera',
37
+ 'B-charging',
38
+ 'I-charging',
39
+ 'B-screen',
40
+ 'I-screen',
41
+ 'B-audio',
42
+ 'I-audio',
43
+ 'B-feature',
44
+ 'I-feature',
45
+ 'B-connection',
46
+ 'I-connection',
47
+ 'B-button',
48
+ 'I-button']
49
+
50
  def analyze_ner(text):
51
  predictions = clf_ner(text)
52
  print(predictions) # Debugging statement to see the structure of the output
 
 
53
  keys = []
54
  values = []
55
 
56
+ for i, label in enumerate(LABEL):
57
+ keys.append(f'LABEL_{i}')
58
+ values.append(label)
59
+
60
 
61
+ label_mapping = { k:v for (k,v) in zip(keys, values) }
62
  results = []
63
  for pred in predictions:
64
  result = f"""Word: {pred['word']}
65
+ Predicted Tag: {label_mapping[pred['entity']]}
66
  Confidence Probability: {pred['score']}\n"""
67
  results.append(result)
68