Corin1998 commited on
Commit
b6b2d84
·
verified ·
1 Parent(s): 7864b3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -27,7 +27,7 @@ def process_resumes(files, candidate_id: str, additional_notes: str = ""):
27
  partial_records = []
28
  raw_texts = []
29
 
30
- # files は 'filepath' 前提(str パスが来る)
31
  for path in files:
32
  filepath = str(path)
33
  filename = os.path.basename(filepath)
@@ -36,16 +36,16 @@ def process_resumes(files, candidate_id: str, additional_notes: str = ""):
36
 
37
  filetype = detect_filetype(filename, raw_bytes)
38
 
39
- # 1) テキスト抽出:画像/PDFはOpenAI Vision OCR、docx/txtは生文面+OpenAI整形
40
  if filetype in {"pdf", "image"}:
41
  text = extract_text_with_openai(raw_bytes, filename=filename, filetype=filetype)
42
- else:
43
  base_text = load_doc_text(filetype, raw_bytes)
44
  text = extract_text_with_openai(base_text.encode("utf-8"), filename=filename, filetype="txt")
45
 
46
  raw_texts.append({"filename": filename, "text": text})
47
 
48
- # 2) OpenAIでセクション構造化ルール正規化
49
  structured = structure_with_openai(text)
50
  normalized = normalize_resume({
51
  "work_experience": structured.get("work_experience_raw", ""),
@@ -60,7 +60,7 @@ def process_resumes(files, candidate_id: str, additional_notes: str = ""):
60
  "normalized": normalized,
61
  })
62
 
63
- # 3) 統合(複数ファイル→1候補者)
64
  merged = merge_normalized_records([r["normalized"] for r in partial_records])
65
 
66
  # 4) スキル抽出
@@ -112,7 +112,7 @@ def process_resumes(files, candidate_id: str, additional_notes: str = ""):
112
 
113
  return (
114
  json.dumps(result_json, ensure_ascii=False, indent=2),
115
- json.dumps(skills, ensure_ascii=False, indent=2), # ← gr.Code に渡すため文字列
116
  json.dumps(score, ensure_ascii=False, indent=2),
117
  summaries["300chars"],
118
  summaries["100chars"],
@@ -130,7 +130,7 @@ with gr.Blocks(title=APP_TITLE) as demo:
130
  label="レジュメ類 (PDF/画像/Word/テキスト) 複数可",
131
  file_count="multiple",
132
  file_types=[".pdf", ".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".docx", ".txt"],
133
- type="filepath", # ← 重要:'file' は不可
134
  )
135
  candidate_id = gr.Textbox(label="候補者ID(任意。未入力なら自動生成)")
136
  notes = gr.Textbox(label="補足メモ(任意)", lines=3)
@@ -141,7 +141,7 @@ with gr.Blocks(title=APP_TITLE) as demo:
141
  out_json = gr.Code(label="統合出力 (JSON)")
142
 
143
  with gr.Tab("抽出スキル"):
144
- out_skills = gr.Code(label="スキル一覧 (JSON)") # ← gr.JSON だと 4.44 で例外が出るケースあり
145
 
146
  with gr.Tab("品質スコア"):
147
  out_score = gr.Code(label="品質評価")
@@ -165,4 +165,4 @@ with gr.Blocks(title=APP_TITLE) as demo:
165
 
166
 
167
  if __name__ == "__main__":
168
- demo.launch(share=True) # ← Spaces環境向け
 
27
  partial_records = []
28
  raw_texts = []
29
 
30
+ # files は 'filepath'(文字列パス)
31
  for path in files:
32
  filepath = str(path)
33
  filename = os.path.basename(filepath)
 
36
 
37
  filetype = detect_filetype(filename, raw_bytes)
38
 
39
+ # 1) テキスト抽出
40
  if filetype in {"pdf", "image"}:
41
  text = extract_text_with_openai(raw_bytes, filename=filename, filetype=filetype)
42
+ else:
43
  base_text = load_doc_text(filetype, raw_bytes)
44
  text = extract_text_with_openai(base_text.encode("utf-8"), filename=filename, filetype="txt")
45
 
46
  raw_texts.append({"filename": filename, "text": text})
47
 
48
+ # 2) 構造化正規化
49
  structured = structure_with_openai(text)
50
  normalized = normalize_resume({
51
  "work_experience": structured.get("work_experience_raw", ""),
 
60
  "normalized": normalized,
61
  })
62
 
63
+ # 3) 統合
64
  merged = merge_normalized_records([r["normalized"] for r in partial_records])
65
 
66
  # 4) スキル抽出
 
112
 
113
  return (
114
  json.dumps(result_json, ensure_ascii=False, indent=2),
115
+ json.dumps(skills, ensure_ascii=False, indent=2), # ← Codeに渡すため文字列に
116
  json.dumps(score, ensure_ascii=False, indent=2),
117
  summaries["300chars"],
118
  summaries["100chars"],
 
130
  label="レジュメ類 (PDF/画像/Word/テキスト) 複数可",
131
  file_count="multiple",
132
  file_types=[".pdf", ".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".docx", ".txt"],
133
+ type="filepath", # ← 重要:'file' ではなく 'filepath'
134
  )
135
  candidate_id = gr.Textbox(label="候補者ID(任意。未入力なら自動生成)")
136
  notes = gr.Textbox(label="補足メモ(任意)", lines=3)
 
141
  out_json = gr.Code(label="統合出力 (JSON)")
142
 
143
  with gr.Tab("抽出スキル"):
144
+ out_skills = gr.Code(label="スキル一覧 (JSON)") # ← gr.JSON から変更
145
 
146
  with gr.Tab("品質スコア"):
147
  out_score = gr.Code(label="品質評価")
 
165
 
166
 
167
  if __name__ == "__main__":
168
+ demo.launch(share=True) # ← 必須