Corin1998 commited on
Commit
7df6a8a
·
verified ·
1 Parent(s): 865007c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
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)
@@ -41,12 +41,12 @@ def process_resumes(files, candidate_id: str, additional_notes: str = ""):
41
  text = extract_text_with_openai(raw_bytes, filename=filename, filetype=filetype)
42
  else:
43
  base_text = load_doc_text(filetype, raw_bytes)
44
- # 生テキストをOpenAIへ渡し、整形済み本文を取得
45
  text = extract_text_with_openai(base_text.encode("utf-8"), filename=filename, filetype="txt")
46
 
47
  raw_texts.append({"filename": filename, "text": text})
48
 
49
- # 2) OpenAIでセクション構造化ルール正規化
50
  structured = structure_with_openai(text)
51
  normalized = normalize_resume({
52
  "work_experience": structured.get("work_experience_raw", ""),
@@ -111,9 +111,10 @@ def process_resumes(files, candidate_id: str, additional_notes: str = ""):
111
 
112
  anon_pdf = (result_json["candidate_id"] + ".anon.pdf", anon_pdf_bytes)
113
 
 
114
  return (
115
  json.dumps(result_json, ensure_ascii=False, indent=2),
116
- json.dumps(skills, ensure_ascii=False, indent=2), # gr.Code に渡すため文字列化
117
  json.dumps(score, ensure_ascii=False, indent=2),
118
  summaries["300chars"],
119
  summaries["100chars"],
@@ -131,7 +132,7 @@ with gr.Blocks(title=APP_TITLE) as demo:
131
  label="レジュメ類 (PDF/画像/Word/テキスト) 複数可",
132
  file_count="multiple",
133
  file_types=[".pdf", ".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".docx", ".txt"],
134
- type="filepath", # Gradio 4.44系は 'filepath' or 'binary'
135
  )
136
  candidate_id = gr.Textbox(label="候補者ID(任意。未入力なら自動生成)")
137
  notes = gr.Textbox(label="補足メモ(任意)", lines=3)
@@ -142,7 +143,7 @@ with gr.Blocks(title=APP_TITLE) as demo:
142
  out_json = gr.Code(label="統合出力 (JSON)")
143
 
144
  with gr.Tab("抽出スキル"):
145
- out_skills = gr.Code(label="スキル一覧 (JSON)") # gr.JSON は 4.44系でスキーマ例外が出ることがあるため回避
146
 
147
  with gr.Tab("品質スコア"):
148
  out_score = gr.Code(label="品質評価")
@@ -166,5 +167,9 @@ with gr.Blocks(title=APP_TITLE) as demo:
166
 
167
 
168
  if __name__ == "__main__":
169
- # Spaces 環境では共有URL必須になる場合があるため share=True を明示
170
- demo.launch(share=True)
 
 
 
 
 
27
  partial_records = []
28
  raw_texts = []
29
 
30
+ # gr.Files(type="filepath") files はパスの配列
31
  for path in files:
32
  filepath = str(path)
33
  filename = os.path.basename(filepath)
 
41
  text = extract_text_with_openai(raw_bytes, filename=filename, filetype=filetype)
42
  else:
43
  base_text = load_doc_text(filetype, raw_bytes)
44
+ # 生テキストをOpenAIへ渡して整形
45
  text = extract_text_with_openai(base_text.encode("utf-8"), filename=filename, filetype="txt")
46
 
47
  raw_texts.append({"filename": filename, "text": text})
48
 
49
+ # 2) 構造化正規化
50
  structured = structure_with_openai(text)
51
  normalized = normalize_resume({
52
  "work_experience": structured.get("work_experience_raw", ""),
 
111
 
112
  anon_pdf = (result_json["candidate_id"] + ".anon.pdf", anon_pdf_bytes)
113
 
114
+ # gr.Code に渡すため、JSONはすべて str にして返す
115
  return (
116
  json.dumps(result_json, ensure_ascii=False, indent=2),
117
+ json.dumps(skills, ensure_ascii=False, indent=2),
118
  json.dumps(score, ensure_ascii=False, indent=2),
119
  summaries["300chars"],
120
  summaries["100chars"],
 
132
  label="レジュメ類 (PDF/画像/Word/テキスト) 複数可",
133
  file_count="multiple",
134
  file_types=[".pdf", ".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".docx", ".txt"],
135
+ type="filepath", # ★重要:Gradio 4.44 'filepath' or 'binary'
136
  )
137
  candidate_id = gr.Textbox(label="候補者ID(任意。未入力なら自動生成)")
138
  notes = gr.Textbox(label="補足メモ(任意)", lines=3)
 
143
  out_json = gr.Code(label="統合出力 (JSON)")
144
 
145
  with gr.Tab("抽出スキル"):
146
+ out_skills = gr.Code(label="スキル一覧 (JSON)") # gr.JSON はスキーマ例外のため回避
147
 
148
  with gr.Tab("品質スコア"):
149
  out_score = gr.Code(label="品質評価")
 
167
 
168
 
169
  if __name__ == "__main__":
170
+ # HF Spaces では share=True は未対応。ローカルでのみ share=True を有効化。
171
+ on_spaces = bool(os.environ.get("SPACE_ID") or os.environ.get("SYSTEM") == "spaces")
172
+ if on_spaces:
173
+ demo.launch(server_name="0.0.0.0", server_port=7860)
174
+ else:
175
+ demo.launch(share=True)