Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,12 +16,21 @@ def parse_fashion_query(query):
|
|
16 |
result = nlp_ner(query)
|
17 |
|
18 |
structured_output = {}
|
|
|
|
|
19 |
for label in result:
|
20 |
entity = label["entity"]
|
21 |
word = label["word"]
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# Gradio UI
|
27 |
with gr.Blocks() as demo:
|
|
|
16 |
result = nlp_ner(query)
|
17 |
|
18 |
structured_output = {}
|
19 |
+
prev_entity = None
|
20 |
+
|
21 |
for label in result:
|
22 |
entity = label["entity"]
|
23 |
word = label["word"]
|
24 |
+
|
25 |
+
# Merge subwords (handling "##tokens")
|
26 |
+
if word.startswith("##") and prev_entity == entity:
|
27 |
+
structured_output[entity][-1] += word[2:]
|
28 |
+
else:
|
29 |
+
structured_output.setdefault(entity, []).append(word)
|
30 |
+
|
31 |
+
prev_entity = entity
|
32 |
+
|
33 |
+
return structured_output, result # Now returns two separate outputs
|
34 |
|
35 |
# Gradio UI
|
36 |
with gr.Blocks() as demo:
|