mannus commited on
Commit
c724c96
·
1 Parent(s): 0f6649e
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -15,15 +15,18 @@ class InputText(BaseModel):
15
  async def segment_text(payload: InputText):
16
  text = payload.text
17
  result = nlp(text)
18
- output = ""
19
- for e in result:
20
- if "##" in e["word"]:
21
- output += e["word"].replace("##", "")
22
- elif e["entity"] == "I":
23
- output += "_" + e["word"]
24
- else:
25
- output += " " + e["word"]
26
- return {"segmented_text": output.strip()}
 
 
 
27
 
28
  @app.get("/")
29
  def greet_json():
 
15
  async def segment_text(payload: InputText):
16
  text = payload.text
17
  result = nlp(text)
18
+ # Convert numpy values to native Python types
19
+ processed_result = []
20
+ for item in result:
21
+ processed_item = {
22
+ 'entity': str(item['entity']),
23
+ 'score': float(item['score']),
24
+ 'word': str(item['word']),
25
+ 'start': int(item['start']),
26
+ 'end': int(item['end'])
27
+ }
28
+ processed_result.append(processed_item)
29
+ return processed_result
30
 
31
  @app.get("/")
32
  def greet_json():