File size: 4,966 Bytes
0c0f923
83f04c7
 
0c0f923
 
83f04c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d3df5a
83f04c7
 
 
 
6507010
 
83f04c7
 
 
 
 
 
 
0c0f923
f7933a5
83f04c7
0c0f923
 
83f04c7
444d088
83f04c7
 
f7933a5
 
 
 
 
 
444d088
 
 
 
 
 
f7933a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07aca08
f7933a5
 
 
 
 
 
 
 
 
 
 
83f04c7
444d088
 
 
 
 
 
 
 
 
 
 
 
 
6507010
444d088
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7933a5
 
 
444d088
 
 
 
 
 
 
07aca08
 
 
444d088
07277a8
f7933a5
83f04c7
f7933a5
07aca08
83f04c7
f7933a5
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import gradio as gr
import io
from PyPDF2 import PdfReader
from app import create_agent

def extract_text_from_pdf(file_obj) -> str:
    reader = PdfReader(file_obj)
    text = ""
    for page in reader.pages:
        page_text = page.extract_text()
        if page_text:
            text += page_text + "\n"
    return text

def process_resume(input_method, resume_text, pdf_file):
    if input_method == "Text":
        text = resume_text
    else:
        if pdf_file is None:
            return "No PDF uploaded."
        # pdf_file may be a file path or a file-like object; handle accordingly
        if isinstance(pdf_file, str):
            with open(pdf_file, "rb") as f:
                file_bytes = f.read()
        else:
            # Ensure the file pointer is at the beginning
            pdf_file.seek(0)
            file_bytes = pdf_file.read()
        file_obj = io.BytesIO(file_bytes)
        text = extract_text_from_pdf(file_obj)
    
    if not text.strip():
        return "No resume text found."
    
    agent = create_agent()
    # Use the agent to roast the resume.
    response = agent.run(f"Roast this resume: {text}")
    return response

def toggle_inputs(method):
    # Toggle PDF and text input visibility.
    if method == "Text":
        return gr.update(visible=False), gr.update(visible=True)
    else:
        return gr.update(visible=True), gr.update(visible=False)

css_custom = """
footer {visibility: hidden;}
.center { 
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
  text-align: center;
  gap: 10px;
}
@keyframes beat {
  0%, 20%, 40%, 60%, 80%, 100% { transform: scale(1); }
  10%, 30%, 50%, 70%, 90% { transform: scale(1.2); }
}
.beating-heart {
  display: inline-block;
  animation: beat 2s infinite;
}
.fire-effect {
  font-size: 2.5em;
  font-weight: bold;
  background: linear-gradient(45deg, red, orange, yellow);
  background-size: 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: fireAnimation 3s linear infinite;
}

@keyframes fireAnimation {
  0% { background-position: 0%; }
  50% { background-position: 100%; }
  100% { background-position: 0%; }
}
/* Center the radio button options */
div[role="radiogroup"] {
  display: flex;
  justify-content: center;
}
"""

import gradio as gr
import io
from PyPDF2 import PdfReader
from app import create_agent

def extract_text_from_pdf(file_obj) -> str:
    reader = PdfReader(file_obj)
    text = ""
    for page in reader.pages:
        page_text = page.extract_text()
        if page_text:
            text += page_text + "\n"
    return text

def process_resume(input_method, resume_text, pdf_file):
    if input_method == "Text":
        text = resume_text
    else:
        if pdf_file is None:
            return "No PDF uploaded."
        if isinstance(pdf_file, str):
            with open(pdf_file, "rb") as f:
                file_bytes = f.read()
        else:
            pdf_file.seek(0)
            file_bytes = pdf_file.read()
        file_obj = io.BytesIO(file_bytes)
        text = extract_text_from_pdf(file_obj)
    
    if not text.strip():
        return "No resume text found."
    
    agent = create_agent()
    response = agent.run(f"Roast this resume: {text}")
    return response

def toggle_inputs(method):
    if method == "Text":
        return gr.update(visible=False), gr.update(visible=True)
    else:
        return gr.update(visible=True), gr.update(visible=False)

with gr.Blocks(css=css_custom, theme=gr.themes.Monochrome()) as demo:
    with gr.Column(elem_classes="center"):
        gr.Markdown('<div class="fire-effect">Resume Roaster</div>')
        gr.Markdown("Upload your resume as a PDF (default) or paste the text to receive a humorous, professional roast!")
        
        # Instead of the built-in label, add a custom left-aligned heading:
        gr.Markdown("<div style='text-align: left; width: 100%; font-weight: bold;'>Select Input Method</div>")
        input_method = gr.Radio(choices=["PDF", "Text"], value="PDF", show_label=False)
        
        # Wrap the file and text inputs in a centered container.
        with gr.Row(elem_classes="center"):
              pdf_file = gr.File(label="Upload Resume PDF", file_types=[".pdf"], visible=True)
              resume_text = gr.Textbox(label="Resume Text", lines=10, visible=False, elem_id="wide-textbox")

        
        outputs=gr.Markdown(label="Roast Result")
        submit_btn = gr.Button("Roast It!")
    
    input_method.change(fn=toggle_inputs, inputs=input_method, outputs=[pdf_file, resume_text])
    submit_btn.click(fn=process_resume, inputs=[input_method, resume_text, pdf_file], outputs=outputs)
    
    gr.Markdown(
        """
        <div id="custom_footer" style="text-align: center; margin-top: 20px; font-size: 14px;">
          All jokes are crafted in good humor to provide professional levity.
        </div>
        """
    )

demo.launch(share=False)