Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,12 @@ from flair.data import Sentence
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
-
# Ladda Flair NER-modell
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Ladda entiteter från entities.json
|
| 13 |
with open("entities.json") as f:
|
|
@@ -35,7 +39,7 @@ async def parse_user_request(request: str):
|
|
| 35 |
|
| 36 |
# Extrahera entiteter
|
| 37 |
result_entities = {}
|
| 38 |
-
#
|
| 39 |
words = request.lower().split()
|
| 40 |
for word in words:
|
| 41 |
if word in COLORS:
|
|
@@ -45,11 +49,11 @@ async def parse_user_request(request: str):
|
|
| 45 |
|
| 46 |
# Extrahera varor från NER
|
| 47 |
for entity in sentence.get_spans("ner"):
|
| 48 |
-
if entity.tag in ["
|
| 49 |
corrected = correct_spelling(entity.text.lower(), ITEMS)
|
| 50 |
if corrected in ITEMS:
|
| 51 |
result_entities["VARA"] = corrected
|
| 52 |
-
elif not result_entities.get("VARA"):
|
| 53 |
result_entities["VARA"] = entity.text.lower()
|
| 54 |
|
| 55 |
# Om ingen vara hittades
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
+
# Ladda Flair flerspråkig NER-modell
|
| 10 |
+
try:
|
| 11 |
+
tagger = SequenceTagger.load("flair/ner-multi")
|
| 12 |
+
except Exception as e:
|
| 13 |
+
print(f"Error loading model: {str(e)}")
|
| 14 |
+
raise e
|
| 15 |
|
| 16 |
# Ladda entiteter från entities.json
|
| 17 |
with open("entities.json") as f:
|
|
|
|
| 39 |
|
| 40 |
# Extrahera entiteter
|
| 41 |
result_entities = {}
|
| 42 |
+
# Kolla färger och priser i hela meningen
|
| 43 |
words = request.lower().split()
|
| 44 |
for word in words:
|
| 45 |
if word in COLORS:
|
|
|
|
| 49 |
|
| 50 |
# Extrahera varor från NER
|
| 51 |
for entity in sentence.get_spans("ner"):
|
| 52 |
+
if entity.tag in ["MISC", "ORG", "LOC"]: # Diverse, organisationer, platser som potentiella objekt
|
| 53 |
corrected = correct_spelling(entity.text.lower(), ITEMS)
|
| 54 |
if corrected in ITEMS:
|
| 55 |
result_entities["VARA"] = corrected
|
| 56 |
+
elif not result_entities.get("VARA"):
|
| 57 |
result_entities["VARA"] = entity.text.lower()
|
| 58 |
|
| 59 |
# Om ingen vara hittades
|