cdcvd commited on
Commit
d693764
·
verified ·
1 Parent(s): c099163

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -1,5 +1,7 @@
1
- from fastapi import FastAPI, HTTPException, UploadFile, File
2
  import pandas as pd
 
 
 
3
  from resume_extractor import ResumeExtractor
4
  from job_description_extractor import JobDescriptionExtractor
5
  from model_trainer import ModelTrainer
@@ -11,8 +13,6 @@ from comparison_utils import (
11
  )
12
  from synthetic_data import create_synthetic_data
13
 
14
- app = FastAPI()
15
-
16
  def main(resume_text, job_description):
17
  openai_api_key = 'sk-proj-bC6H6QrP6DUqHkn5vOkYT3BlbkFJsSyvL4Bc9c3UEbHrsPMj'
18
  ner_model_name_or_path = "NLPclass/Named-entity-recognition"
@@ -59,17 +59,26 @@ def main(resume_text, job_description):
59
  "predicted_target": predicted_target[0]
60
  }
61
 
62
- @app.post("/extract")
63
- async def extract(resume_file: UploadFile = File(...), job_description_file: UploadFile = File(...)):
64
  try:
65
- resume_text = await resume_file.read()
66
- job_description = await job_description_file.read()
67
-
68
- # Convert bytes to string
69
- resume_text = resume_text.decode('utf-8')
70
- job_description = job_description.decode('utf-8')
71
 
72
  output = main(resume_text, job_description)
73
- return output
 
 
 
74
  except Exception as e:
75
- raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
+ import tempfile
3
+ import json
4
+ import gradio as gr
5
  from resume_extractor import ResumeExtractor
6
  from job_description_extractor import JobDescriptionExtractor
7
  from model_trainer import ModelTrainer
 
13
  )
14
  from synthetic_data import create_synthetic_data
15
 
 
 
16
  def main(resume_text, job_description):
17
  openai_api_key = 'sk-proj-bC6H6QrP6DUqHkn5vOkYT3BlbkFJsSyvL4Bc9c3UEbHrsPMj'
18
  ner_model_name_or_path = "NLPclass/Named-entity-recognition"
 
59
  "predicted_target": predicted_target[0]
60
  }
61
 
62
+ def process_files(resume_file, job_description_file):
 
63
  try:
64
+ resume_text = resume_file.read().decode('utf-8')
65
+ job_description = job_description_file.read().decode('utf-8')
 
 
 
 
66
 
67
  output = main(resume_text, job_description)
68
+
69
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".json", mode='w', encoding='utf-8') as tmp_file:
70
+ json.dump(output, tmp_file, ensure_ascii=False, indent=4)
71
+ return tmp_file.name
72
  except Exception as e:
73
+ return {"error": str(e)}
74
+
75
+ iface = gr.Interface(
76
+ fn=process_files,
77
+ inputs=[gr.File(label="رزومه (فایل .txt)"), gr.File(label="توضیحات شغل (فایل .txt)")],
78
+ outputs=gr.File(label="دانلود فایل JSON"),
79
+ title="پردازش رزومه و توضیحات شغلی",
80
+ description="این ابزار رزومه و توضیحات شغلی شما را پردازش کرده و امتیازات مشابهت را محاسبه می‌کند."
81
+ )
82
+
83
+ if __name__ == "__main__":
84
+ iface.launch()