Spaces:
Sleeping
Sleeping
Commit
·
444d088
1
Parent(s):
6507010
Better CSS
Browse files
main.py
CHANGED
@@ -38,7 +38,7 @@ def process_resume(input_method, resume_text, pdf_file):
|
|
38 |
return response
|
39 |
|
40 |
def toggle_inputs(method):
|
41 |
-
#
|
42 |
if method == "Text":
|
43 |
return gr.update(visible=False), gr.update(visible=True)
|
44 |
else:
|
@@ -47,8 +47,12 @@ def toggle_inputs(method):
|
|
47 |
css_custom = """
|
48 |
footer {visibility: hidden;}
|
49 |
.center {
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
@keyframes beat {
|
54 |
0%, 20%, 40%, 60%, 80%, 100% { transform: scale(1); }
|
@@ -79,23 +83,65 @@ div[role="radiogroup"] {
|
|
79 |
}
|
80 |
"""
|
81 |
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
with gr.Column(elem_classes="center"):
|
87 |
gr.Markdown('<div class="fire-effect">Resume Roaster</div>')
|
88 |
gr.Markdown("Upload your resume as a PDF (default) or paste the text to receive a humorous, professional roast!")
|
89 |
-
|
90 |
-
#
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
95 |
output = gr.Textbox(label="Roast Result", lines=10)
|
96 |
submit_btn = gr.Button("Roast It!")
|
97 |
|
98 |
-
# Adjust toggle outputs to match new order.
|
99 |
input_method.change(fn=toggle_inputs, inputs=input_method, outputs=[pdf_file, resume_text])
|
100 |
submit_btn.click(fn=process_resume, inputs=[input_method, resume_text, pdf_file], outputs=output)
|
101 |
|
|
|
38 |
return response
|
39 |
|
40 |
def toggle_inputs(method):
|
41 |
+
# Toggle PDF and text input visibility.
|
42 |
if method == "Text":
|
43 |
return gr.update(visible=False), gr.update(visible=True)
|
44 |
else:
|
|
|
47 |
css_custom = """
|
48 |
footer {visibility: hidden;}
|
49 |
.center {
|
50 |
+
display: flex;
|
51 |
+
flex-direction: column;
|
52 |
+
align-items: center;
|
53 |
+
margin: 0 auto;
|
54 |
+
text-align: center;
|
55 |
+
gap: 10px;
|
56 |
}
|
57 |
@keyframes beat {
|
58 |
0%, 20%, 40%, 60%, 80%, 100% { transform: scale(1); }
|
|
|
83 |
}
|
84 |
"""
|
85 |
|
86 |
+
import gradio as gr
|
87 |
+
import io
|
88 |
+
from PyPDF2 import PdfReader
|
89 |
+
from app import create_agent
|
90 |
+
|
91 |
+
def extract_text_from_pdf(file_obj) -> str:
|
92 |
+
reader = PdfReader(file_obj)
|
93 |
+
text = ""
|
94 |
+
for page in reader.pages:
|
95 |
+
page_text = page.extract_text()
|
96 |
+
if page_text:
|
97 |
+
text += page_text + "\n"
|
98 |
+
return text
|
99 |
|
100 |
+
def process_resume(input_method, resume_text, pdf_file):
|
101 |
+
if input_method == "Text":
|
102 |
+
text = resume_text
|
103 |
+
else:
|
104 |
+
if pdf_file is None:
|
105 |
+
return "No PDF uploaded."
|
106 |
+
if isinstance(pdf_file, str):
|
107 |
+
with open(pdf_file, "rb") as f:
|
108 |
+
file_bytes = f.read()
|
109 |
+
else:
|
110 |
+
pdf_file.seek(0)
|
111 |
+
file_bytes = pdf_file.read()
|
112 |
+
file_obj = io.BytesIO(file_bytes)
|
113 |
+
text = extract_text_from_pdf(file_obj)
|
114 |
+
|
115 |
+
if not text.strip():
|
116 |
+
return "No resume text found."
|
117 |
+
|
118 |
+
agent = create_agent()
|
119 |
+
response = agent.run(f"Roast this resume: {text}")
|
120 |
+
return response
|
121 |
+
|
122 |
+
def toggle_inputs(method):
|
123 |
+
if method == "Text":
|
124 |
+
return gr.update(visible=False), gr.update(visible=True)
|
125 |
+
else:
|
126 |
+
return gr.update(visible=True), gr.update(visible=False)
|
127 |
+
|
128 |
+
with gr.Blocks(css=css_custom, theme=gr.themes.Monochrome()) as demo:
|
129 |
with gr.Column(elem_classes="center"):
|
130 |
gr.Markdown('<div class="fire-effect">Resume Roaster</div>')
|
131 |
gr.Markdown("Upload your resume as a PDF (default) or paste the text to receive a humorous, professional roast!")
|
132 |
+
|
133 |
+
# Instead of the built-in label, add a custom left-aligned heading:
|
134 |
+
gr.Markdown("<div style='text-align: left; width: 100%; font-weight: bold;'>Select Input Method</div>")
|
135 |
+
input_method = gr.Radio(choices=["PDF", "Text"], value="PDF", show_label=False)
|
136 |
+
|
137 |
+
# Wrap the file and text inputs in a centered container.
|
138 |
+
with gr.Row(elem_classes="center"):
|
139 |
+
pdf_file = gr.File(label="Upload Resume PDF", file_types=[".pdf"], visible=True)
|
140 |
+
resume_text = gr.Textbox(label="Resume Text", lines=10, visible=False)
|
141 |
+
|
142 |
output = gr.Textbox(label="Roast Result", lines=10)
|
143 |
submit_btn = gr.Button("Roast It!")
|
144 |
|
|
|
145 |
input_method.change(fn=toggle_inputs, inputs=input_method, outputs=[pdf_file, resume_text])
|
146 |
submit_btn.click(fn=process_resume, inputs=[input_method, resume_text, pdf_file], outputs=output)
|
147 |
|