Wind-xixi commited on
Commit
b56984a
·
verified ·
1 Parent(s): 99f4beb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -10,8 +10,7 @@ app = FastAPI()
10
  # 初始化 SentenceExtractor
11
  extractor = SentenceExtractor(
12
  eval_keywords_path="evaluation_keywords2.json",
13
- model_path="model_quantized.onnx",
14
- use_model=False # 先使用基于关键词的启发式评分,避免不匹配的预处理导致伪随机结果
15
  )
16
 
17
  @app.get("/")
@@ -28,7 +27,22 @@ async def evaluate_file(file: UploadFile = File(...)):
28
  # 调用 extractor 进行文本分析
29
  result = extractor.extract(text)
30
 
31
- return JSONResponse(content=result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  except Exception as e:
34
  return JSONResponse(content={"error": str(e)}, status_code=500)
@@ -39,5 +53,3 @@ if __name__ == "__main__":
39
  uvicorn.run("app:app", host="0.0.0.0", port=port)
40
 
41
 
42
-
43
-
 
10
  # 初始化 SentenceExtractor
11
  extractor = SentenceExtractor(
12
  eval_keywords_path="evaluation_keywords2.json",
13
+ model_path="model_quantized.onnx"
 
14
  )
15
 
16
  @app.get("/")
 
27
  # 调用 extractor 进行文本分析
28
  result = extractor.extract(text)
29
 
30
+ # 格式化输出结果
31
+ formatted_result = {
32
+ "综合评分": result["comprehensive_grade"],
33
+ "积极词语评价数": result["positive_word_count"],
34
+ "消极词语评价数": result["negative_word_count"],
35
+ "中性词语评价数": result["neutral_word_count"],
36
+ "句子评分": []
37
+ }
38
+
39
+ # 添加句子评分信息
40
+ for i, item in enumerate(result["scored_sentences"], 1):
41
+ formatted_result["句子评分"].append({
42
+ f"句子{i}": f"{item['sentence']} - {item['grade']}"
43
+ })
44
+
45
+ return JSONResponse(content=formatted_result)
46
 
47
  except Exception as e:
48
  return JSONResponse(content={"error": str(e)}, status_code=500)
 
53
  uvicorn.run("app:app", host="0.0.0.0", port=port)
54
 
55