Update app.py
Browse files
app.py
CHANGED
|
@@ -55,30 +55,21 @@ def extract_text_from_docx(docx_file):
|
|
| 55 |
text += para.text + "\n"
|
| 56 |
return text
|
| 57 |
|
| 58 |
-
def generate_response(message: str,
|
| 59 |
conversation = [
|
| 60 |
-
{"role": "system", "content": system_prompt}
|
|
|
|
| 61 |
]
|
| 62 |
-
for prompt, answer in history:
|
| 63 |
-
conversation.extend([
|
| 64 |
-
{"role": "user", "content": prompt},
|
| 65 |
-
{"role": "assistant", "content": answer},
|
| 66 |
-
])
|
| 67 |
-
conversation.append({"role": "user", "content": message})
|
| 68 |
|
| 69 |
response = client.chat.completions.create(
|
| 70 |
model="llama-3.1-8B-Instant",
|
| 71 |
messages=conversation,
|
| 72 |
temperature=temperature,
|
| 73 |
max_tokens=max_tokens,
|
| 74 |
-
stream=
|
| 75 |
)
|
| 76 |
|
| 77 |
-
|
| 78 |
-
for chunk in response:
|
| 79 |
-
if chunk.choices[0].delta.content is not None:
|
| 80 |
-
partial_message += chunk.choices[0].delta.content
|
| 81 |
-
yield partial_message
|
| 82 |
|
| 83 |
def analyze_resume(resume_text, job_description):
|
| 84 |
prompt = f"""
|
|
@@ -92,7 +83,7 @@ def analyze_resume(resume_text, job_description):
|
|
| 92 |
Job Description: {job_description}
|
| 93 |
Resume: {resume_text}
|
| 94 |
"""
|
| 95 |
-
return generate_response(prompt,
|
| 96 |
|
| 97 |
def rephrase_text(text):
|
| 98 |
prompt = f"""
|
|
@@ -100,7 +91,7 @@ def rephrase_text(text):
|
|
| 100 |
|
| 101 |
Original Text: {text}
|
| 102 |
"""
|
| 103 |
-
return generate_response(prompt,
|
| 104 |
|
| 105 |
def clear_conversation():
|
| 106 |
return [], None
|
|
@@ -124,10 +115,6 @@ with gr.Blocks(css=CSS, theme="Nymbo/Nymbo_Theme") as demo:
|
|
| 124 |
rephrased_output = gr.Markdown()
|
| 125 |
|
| 126 |
with gr.Accordion("⚙️ Parameters", open=False):
|
| 127 |
-
system_prompt = gr.Textbox(
|
| 128 |
-
value="You are a helpful ATS resume expert, specialized in resume analysis and optimization.",
|
| 129 |
-
label="System Prompt",
|
| 130 |
-
)
|
| 131 |
temperature = gr.Slider(
|
| 132 |
minimum=0, maximum=1, step=0.1, value=0.5, label="Temperature",
|
| 133 |
)
|
|
|
|
| 55 |
text += para.text + "\n"
|
| 56 |
return text
|
| 57 |
|
| 58 |
+
def generate_response(message: str, system_prompt: str, temperature: float = 0.5, max_tokens: int = 512):
|
| 59 |
conversation = [
|
| 60 |
+
{"role": "system", "content": system_prompt},
|
| 61 |
+
{"role": "user", "content": message}
|
| 62 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
response = client.chat.completions.create(
|
| 65 |
model="llama-3.1-8B-Instant",
|
| 66 |
messages=conversation,
|
| 67 |
temperature=temperature,
|
| 68 |
max_tokens=max_tokens,
|
| 69 |
+
stream=False
|
| 70 |
)
|
| 71 |
|
| 72 |
+
return response.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
def analyze_resume(resume_text, job_description):
|
| 75 |
prompt = f"""
|
|
|
|
| 83 |
Job Description: {job_description}
|
| 84 |
Resume: {resume_text}
|
| 85 |
"""
|
| 86 |
+
return generate_response(prompt, "You are an expert ATS resume analyzer.")
|
| 87 |
|
| 88 |
def rephrase_text(text):
|
| 89 |
prompt = f"""
|
|
|
|
| 91 |
|
| 92 |
Original Text: {text}
|
| 93 |
"""
|
| 94 |
+
return generate_response(prompt, "You are an expert in rephrasing content for ATS optimization.")
|
| 95 |
|
| 96 |
def clear_conversation():
|
| 97 |
return [], None
|
|
|
|
| 115 |
rephrased_output = gr.Markdown()
|
| 116 |
|
| 117 |
with gr.Accordion("⚙️ Parameters", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
temperature = gr.Slider(
|
| 119 |
minimum=0, maximum=1, step=0.1, value=0.5, label="Temperature",
|
| 120 |
)
|