Upload folder using huggingface_hub
Browse files
pipe.py
CHANGED
@@ -89,27 +89,21 @@ class AudioSpeechNERPipeline:
|
|
89 |
|
90 |
return transcription, entities
|
91 |
|
92 |
-
def
|
93 |
-
|
94 |
-
Create HTML representation of named entities
|
95 |
-
"""
|
96 |
-
if not entities:
|
97 |
-
return "No named entities found."
|
98 |
-
|
99 |
-
html = "<div style='background-color:#f0f0f0; padding:10px; border-radius:5px;'>"
|
100 |
-
html += "<h3>Named Entities:</h3>"
|
101 |
-
html += "<table style='width:100%; border-collapse:collapse;'>"
|
102 |
-
html += "<tr><th style='border:1px solid #ddd; padding:8px;'>Word</th><th style='border:1px solid #ddd; padding:8px;'>Entity Type</th></tr>"
|
103 |
|
104 |
for entity in entities:
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
113 |
|
114 |
def process_audio_pipeline(audio):
|
115 |
"""
|
@@ -121,11 +115,9 @@ def process_audio_pipeline(audio):
|
|
121 |
try:
|
122 |
# Process the audio
|
123 |
transcription, entities = pipeline.process_audio(audio)
|
|
|
124 |
|
125 |
-
|
126 |
-
entities_html = create_ner_html(entities)
|
127 |
-
|
128 |
-
return transcription, entities_html
|
129 |
|
130 |
except Exception as e:
|
131 |
return f"Error processing audio: {str(e)}", ""
|
|
|
89 |
|
90 |
return transcription, entities
|
91 |
|
92 |
+
def replace_ner(entities):
|
93 |
+
processed_entities = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
for entity in entities:
|
96 |
+
number = int(entity['entity'].split("_")[-1])
|
97 |
+
|
98 |
+
# Skip entities with number 0
|
99 |
+
if number == 0:
|
100 |
+
continue
|
101 |
+
|
102 |
+
# Create a copy of the entity and update the label
|
103 |
+
updated_entity = entity.copy()
|
104 |
+
updated_entity['entity'] = labels[number]
|
105 |
+
processed_entities.append(updated_entity)
|
106 |
+
return processed_entities
|
107 |
|
108 |
def process_audio_pipeline(audio):
|
109 |
"""
|
|
|
115 |
try:
|
116 |
# Process the audio
|
117 |
transcription, entities = pipeline.process_audio(audio)
|
118 |
+
entities = replace_ner(entities)
|
119 |
|
120 |
+
return transcription, entities
|
|
|
|
|
|
|
121 |
|
122 |
except Exception as e:
|
123 |
return f"Error processing audio: {str(e)}", ""
|