Kuberwastaken commited on
Commit
22351fe
·
1 Parent(s): 792785c

Improved app structure

Browse files
Files changed (2) hide show
  1. app.py +52 -43
  2. prompts.yaml +11 -13
app.py CHANGED
@@ -1,49 +1,58 @@
1
- import yaml
2
- from smolagents import CodeAgent, HfApiModel
3
- from smolagents.tools import Tool
4
- from tools.resumescraper import ResumeScraperTool
5
- from huggingface_hub import InferenceClient
6
 
7
- class FinalAnswerTool(Tool):
8
- name = "final_answer"
9
- description = "Use this tool to provide your final roast"
10
- inputs = {
11
- "answer": {
12
- "type": "string",
13
- "description": "The final roast for the resume"
14
- }
15
- }
16
- output_type = "string"
17
 
18
- def forward(self, answer: str) -> str:
19
- return answer
20
-
21
- def create_agent():
22
- final_answer = FinalAnswerTool()
23
- resume_scraper = ResumeScraperTool()
 
 
 
 
 
 
 
 
24
 
25
- # Instantiate HfApiModel using Qwen/Qwen2.5-Coder-32B-Instruct for roasting.
26
- model = HfApiModel(
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
- # Create a dedicated InferenceClient using your public endpoint
34
- client = InferenceClient("https://jc26mwg228mkj8dw.us-east-1.aws.endpoints.huggingface.cloud")
35
- # Override the model's client with our dedicated client
36
- model.client = client
 
 
 
 
 
 
 
37
 
38
- with open("prompts.yaml", 'r') as stream:
39
- prompt_templates = yaml.safe_load(stream)
40
-
41
- agent = CodeAgent(
42
- model=model,
43
- tools=[resume_scraper, final_answer],
44
- max_steps=6,
45
- verbosity_level=1,
46
- prompt_templates=prompt_templates
47
- )
 
 
48
 
49
- return agent
 
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 roasts resumes.
3
- Your job is to create a humorous roast of a resume based solely on its content.
4
- Keep the tone light, semi-professional, and extremely entertaining, with puns and jokes.
5
- Add Meta jokes for Resume being too big, too short, other improvements and roasting if there is something funny on there, like casual buzzwords.
6
-
7
  task_prompt: |
8
- Given the provided resume details, craft a roast that:
9
- 1. References key sections such as Education, Projects, and Skills.
10
- 2. Is humorous yet semi-professional.
11
- 3. Outputs plain text without any code formatting.
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: ""