Spaces:
Running
Running
Commit
·
22351fe
1
Parent(s):
792785c
Improved app structure
Browse files- app.py +52 -43
- prompts.yaml +11 -13
app.py
CHANGED
@@ -1,49 +1,58 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
from
|
4 |
-
from
|
5 |
-
from huggingface_hub import InferenceClient
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
}
|
16 |
-
output_type = "string"
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
max_tokens=2096,
|
28 |
-
temperature=0.5,
|
29 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
30 |
-
custom_role_conversions=None,
|
31 |
-
)
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
|
49 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import io
|
3 |
+
from PyPDF2 import PdfReader
|
4 |
+
from app import create_agent
|
|
|
5 |
|
6 |
+
def extract_text_from_pdf(file_obj) -> str:
|
7 |
+
reader = PdfReader(file_obj)
|
8 |
+
text = ""
|
9 |
+
for page in reader.pages:
|
10 |
+
page_text = page.extract_text()
|
11 |
+
if page_text:
|
12 |
+
text += page_text + "\n"
|
13 |
+
return text
|
|
|
|
|
14 |
|
15 |
+
def process_resume(input_method, resume_text, pdf_file):
|
16 |
+
if input_method == "Text":
|
17 |
+
text = resume_text
|
18 |
+
else:
|
19 |
+
if pdf_file is None:
|
20 |
+
return "No PDF uploaded."
|
21 |
+
# Check if pdf_file is a string (i.e. a file path) or a file-like object
|
22 |
+
if isinstance(pdf_file, str):
|
23 |
+
with open(pdf_file, "rb") as f:
|
24 |
+
file_bytes = f.read()
|
25 |
+
else:
|
26 |
+
file_bytes = pdf_file.read()
|
27 |
+
file_obj = io.BytesIO(file_bytes)
|
28 |
+
text = extract_text_from_pdf(file_obj)
|
29 |
|
30 |
+
if not text.strip():
|
31 |
+
return "No resume text found."
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
agent = create_agent()
|
34 |
+
# Instruct the agent to roast the resume using the resume text.
|
35 |
+
response = agent.run(f"Roast this resume: {text}")
|
36 |
+
return response
|
37 |
+
|
38 |
+
|
39 |
+
def toggle_inputs(method):
|
40 |
+
if method == "Text":
|
41 |
+
return gr.update(visible=True), gr.update(visible=False)
|
42 |
+
else:
|
43 |
+
return gr.update(visible=False), gr.update(visible=True)
|
44 |
|
45 |
+
with gr.Blocks() as demo:
|
46 |
+
gr.Markdown("# Resume Roaster")
|
47 |
+
gr.Markdown("Enter your resume as text or upload a PDF to receive a humorous, professional roast!")
|
48 |
+
|
49 |
+
input_method = gr.Radio(choices=["Text", "PDF"], label="Input Method", value="Text")
|
50 |
+
resume_text = gr.Textbox(label="Resume Text", lines=10, visible=True)
|
51 |
+
pdf_file = gr.File(label="Upload Resume PDF", file_types=[".pdf"], visible=False)
|
52 |
+
output = gr.Textbox(label="Roast Result", lines=10)
|
53 |
+
submit_btn = gr.Button("Roast It!")
|
54 |
+
|
55 |
+
input_method.change(fn=toggle_inputs, inputs=input_method, outputs=[resume_text, pdf_file])
|
56 |
+
submit_btn.click(fn=process_resume, inputs=[input_method, resume_text, pdf_file], outputs=output)
|
57 |
|
58 |
+
demo.launch(share=True)
|
prompts.yaml
CHANGED
@@ -1,16 +1,14 @@
|
|
1 |
system_prompt: |
|
2 |
-
You are a witty professional roaster who
|
3 |
-
Your job is to create a humorous roast of a resume
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
task_prompt: |
|
8 |
-
|
9 |
-
1. References key sections such as
|
10 |
-
2. Is humorous
|
11 |
-
3.
|
12 |
-
|
13 |
final_answer:
|
14 |
-
pre_messages: "Final Roast:
|
15 |
-
post_messages: ""
|
16 |
-
instructions: "Output your final roast as plain text with no code blocks."
|
|
|
1 |
system_prompt: |
|
2 |
+
You are a witty SEMI-professional roaster who analyzes resumes.
|
3 |
+
Your job is to create a humorous, professional roast of a resume.
|
4 |
+
Focus on teasing overly verbose descriptions, excessive buzzwords, and generic statements,
|
5 |
+
while keeping the tone light and appropriate for a professional setting.
|
|
|
6 |
task_prompt: |
|
7 |
+
Using the provided resume details, craft a roast that:
|
8 |
+
1. References key sections such as Summary, Experience, Education, and Skills.
|
9 |
+
2. Is humorous but not mean-spirited.
|
10 |
+
3. Maintains a professional tone.
|
11 |
+
4. Adds creative flair that makes the roast both entertaining and insightful.
|
12 |
final_answer:
|
13 |
+
pre_messages: "Final Roast:"
|
14 |
+
post_messages: ""
|
|