Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -107,28 +107,16 @@ def respond(message, history: list[tuple[str, str]], system_message, max_tokens,
|
|
107 |
yield f"Error during chat generation: {e}"
|
108 |
|
109 |
def create_pdf_report(report_text):
|
110 |
-
"""
|
111 |
-
Creates a PDF from the given report text and returns a dictionary:
|
112 |
-
{
|
113 |
-
"name": "analysis_report.pdf",
|
114 |
-
"data": bytes_of_pdf,
|
115 |
-
"mime_type": "application/pdf"
|
116 |
-
}
|
117 |
-
which gr.File can accept as output.
|
118 |
-
"""
|
119 |
if not report_text.strip():
|
120 |
-
# If there's no report, just return a basic PDF stating so
|
121 |
report_text = "No analysis report to convert."
|
122 |
|
123 |
-
# Use ReportLab to generate PDF in-memory
|
124 |
pdf_buffer = io.BytesIO()
|
125 |
c = canvas.Canvas(pdf_buffer, pagesize=letter)
|
126 |
|
127 |
-
# Title
|
128 |
c.setFont("Helvetica-Bold", 14)
|
129 |
c.drawString(72, 750, "Analysis Report")
|
130 |
|
131 |
-
# Body
|
132 |
text_obj = c.beginText(72, 730)
|
133 |
text_obj.setFont("Helvetica", 11)
|
134 |
for line in report_text.split("\n"):
|
@@ -146,16 +134,8 @@ def create_pdf_report(report_text):
|
|
146 |
}
|
147 |
|
148 |
def toggle_download_button(analysis_report):
|
149 |
-
"""
|
150 |
-
|
151 |
-
"""
|
152 |
-
if analysis_report.strip():
|
153 |
-
# Enable and make it visible
|
154 |
-
return gr.update(interactive=True, visible=True)
|
155 |
-
else:
|
156 |
-
# Hide and disable
|
157 |
-
return gr.update(interactive=False, visible=False)
|
158 |
-
|
159 |
|
160 |
# Build the Gradio UI
|
161 |
demo = gr.Blocks()
|
@@ -181,8 +161,11 @@ with demo:
|
|
181 |
job_desc_input = gr.Textbox(label="Job Description", lines=5)
|
182 |
extracted_text = gr.Textbox(label="Extracted CV Content", lines=10, interactive=False)
|
183 |
analysis_output = gr.Textbox(label="Analysis Report", lines=10, interactive=False)
|
|
|
|
|
184 |
|
185 |
analyze_button = gr.Button("Analyze CV")
|
|
|
186 |
analyze_button.click(
|
187 |
parse_cv,
|
188 |
inputs=[file_input, job_desc_input],
|
@@ -190,25 +173,14 @@ with demo:
|
|
190 |
).then(
|
191 |
toggle_download_button,
|
192 |
inputs=[analysis_output],
|
193 |
-
outputs=[] # we'll update the download button below
|
194 |
-
)
|
195 |
-
|
196 |
-
# Button to generate/download PDF
|
197 |
-
download_pdf_button = gr.Button("Download Analysis as PDF", visible=False, interactive=False)
|
198 |
-
pdf_file = gr.File(label="Download PDF", file_count="single", interactive=False)
|
199 |
-
|
200 |
-
# Chain a .then() so that once parse_cv finishes, we toggle the PDF button
|
201 |
-
analyze_button.then(
|
202 |
-
fn=toggle_download_button,
|
203 |
-
inputs=[analysis_output],
|
204 |
outputs=[download_pdf_button]
|
205 |
)
|
206 |
|
207 |
download_pdf_button.click(
|
208 |
create_pdf_report,
|
209 |
-
inputs=[analysis_output],
|
210 |
-
outputs=[pdf_file]
|
211 |
)
|
212 |
|
213 |
if __name__ == "__main__":
|
214 |
-
demo.queue().launch()
|
|
|
107 |
yield f"Error during chat generation: {e}"
|
108 |
|
109 |
def create_pdf_report(report_text):
|
110 |
+
"""Creates a PDF report."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
if not report_text.strip():
|
|
|
112 |
report_text = "No analysis report to convert."
|
113 |
|
|
|
114 |
pdf_buffer = io.BytesIO()
|
115 |
c = canvas.Canvas(pdf_buffer, pagesize=letter)
|
116 |
|
|
|
117 |
c.setFont("Helvetica-Bold", 14)
|
118 |
c.drawString(72, 750, "Analysis Report")
|
119 |
|
|
|
120 |
text_obj = c.beginText(72, 730)
|
121 |
text_obj.setFont("Helvetica", 11)
|
122 |
for line in report_text.split("\n"):
|
|
|
134 |
}
|
135 |
|
136 |
def toggle_download_button(analysis_report):
|
137 |
+
"""Toggle the download button."""
|
138 |
+
return gr.update(interactive=bool(analysis_report.strip()), visible=bool(analysis_report.strip()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
# Build the Gradio UI
|
141 |
demo = gr.Blocks()
|
|
|
161 |
job_desc_input = gr.Textbox(label="Job Description", lines=5)
|
162 |
extracted_text = gr.Textbox(label="Extracted CV Content", lines=10, interactive=False)
|
163 |
analysis_output = gr.Textbox(label="Analysis Report", lines=10, interactive=False)
|
164 |
+
download_pdf_button = gr.Button("Download Analysis as PDF", visible=False, interactive=False)
|
165 |
+
pdf_file = gr.File(label="Download PDF", file_count="single", interactive=False)
|
166 |
|
167 |
analyze_button = gr.Button("Analyze CV")
|
168 |
+
|
169 |
analyze_button.click(
|
170 |
parse_cv,
|
171 |
inputs=[file_input, job_desc_input],
|
|
|
173 |
).then(
|
174 |
toggle_download_button,
|
175 |
inputs=[analysis_output],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
outputs=[download_pdf_button]
|
177 |
)
|
178 |
|
179 |
download_pdf_button.click(
|
180 |
create_pdf_report,
|
181 |
+
inputs=[analysis_output],
|
182 |
+
outputs=[pdf_file]
|
183 |
)
|
184 |
|
185 |
if __name__ == "__main__":
|
186 |
+
demo.queue().launch()
|