Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import html
|
|
| 6 |
import os
|
| 7 |
import logging
|
| 8 |
import subprocess
|
|
|
|
| 9 |
|
| 10 |
# Set up logging
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -489,7 +490,7 @@ def generate_portfolio(file, theme="Light"):
|
|
| 489 |
try:
|
| 490 |
if not file:
|
| 491 |
logger.error("No file uploaded.")
|
| 492 |
-
return "Error: No file uploaded. Please upload a resume file (PDF or text).", "Error: No file uploaded. Please upload a resume file (PDF or text)."
|
| 493 |
|
| 494 |
# In Hugging Face Spaces, file.name is the path to the uploaded file
|
| 495 |
file_path = file.name if hasattr(file, 'name') else file
|
|
@@ -503,7 +504,7 @@ def generate_portfolio(file, theme="Light"):
|
|
| 503 |
|
| 504 |
if "Error" in resume_text:
|
| 505 |
logger.error(f"Failed to extract text: {resume_text}")
|
| 506 |
-
return resume_text, resume_text
|
| 507 |
|
| 508 |
# Extract details from the resume
|
| 509 |
name, email, phone, education_html, experience_html, projects_html, skills_html, involvement_html, skills_summary, skills = extract_details(resume_text)
|
|
@@ -525,33 +526,17 @@ def generate_portfolio(file, theme="Light"):
|
|
| 525 |
with open("index.html", "w", encoding="utf-8") as f:
|
| 526 |
f.write(html_code)
|
| 527 |
|
| 528 |
-
#
|
| 529 |
html_preview = f"""
|
| 530 |
-
<
|
| 531 |
-
|
| 532 |
-
<p style='text-align: center;'>{skills_summary}</p>
|
| 533 |
-
<h2>Education</h2>
|
| 534 |
-
{education_html}
|
| 535 |
-
<h2>Work Experience</h2>
|
| 536 |
-
{experience_html}
|
| 537 |
-
<h2>Projects</h2>
|
| 538 |
-
{projects_html}
|
| 539 |
-
<h2>Skills</h2>
|
| 540 |
-
<div style='display: flex; flex-wrap: wrap; gap: 10px;'>
|
| 541 |
-
{skills_html}
|
| 542 |
-
</div>
|
| 543 |
-
<h2>Involvement</h2>
|
| 544 |
-
{involvement_html}
|
| 545 |
-
<h2>Contact</h2>
|
| 546 |
-
<p>Email: {email} | Phone: {phone}</p>
|
| 547 |
-
</div>
|
| 548 |
"""
|
| 549 |
|
| 550 |
logger.info("Successfully generated portfolio.")
|
| 551 |
-
return html_preview, html_code
|
| 552 |
except Exception as e:
|
| 553 |
logger.error(f"Error generating portfolio: {str(e)}")
|
| 554 |
-
return f"Error generating portfolio: {str(e)}", f"Error generating portfolio: {str(e)}"
|
| 555 |
|
| 556 |
# Gradio Interface
|
| 557 |
with gr.Blocks() as interface:
|
|
@@ -562,11 +547,12 @@ with gr.Blocks() as interface:
|
|
| 562 |
|
| 563 |
html_output = gr.HTML(label="Portfolio Preview")
|
| 564 |
code_output = gr.Textbox(label="Downloadable HTML/CSS Code", lines=10)
|
|
|
|
| 565 |
|
| 566 |
generate_btn.click(
|
| 567 |
fn=generate_portfolio,
|
| 568 |
inputs=[file_input, theme_input],
|
| 569 |
-
outputs=[html_output, code_output]
|
| 570 |
)
|
| 571 |
|
| 572 |
interface.launch()
|
|
|
|
| 6 |
import os
|
| 7 |
import logging
|
| 8 |
import subprocess
|
| 9 |
+
from urllib.parse import quote
|
| 10 |
|
| 11 |
# Set up logging
|
| 12 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 490 |
try:
|
| 491 |
if not file:
|
| 492 |
logger.error("No file uploaded.")
|
| 493 |
+
return "Error: No file uploaded. Please upload a resume file (PDF or text).", "Error: No file uploaded. Please upload a resume file (PDF or text).", None
|
| 494 |
|
| 495 |
# In Hugging Face Spaces, file.name is the path to the uploaded file
|
| 496 |
file_path = file.name if hasattr(file, 'name') else file
|
|
|
|
| 504 |
|
| 505 |
if "Error" in resume_text:
|
| 506 |
logger.error(f"Failed to extract text: {resume_text}")
|
| 507 |
+
return resume_text, resume_text, None
|
| 508 |
|
| 509 |
# Extract details from the resume
|
| 510 |
name, email, phone, education_html, experience_html, projects_html, skills_html, involvement_html, skills_summary, skills = extract_details(resume_text)
|
|
|
|
| 526 |
with open("index.html", "w", encoding="utf-8") as f:
|
| 527 |
f.write(html_code)
|
| 528 |
|
| 529 |
+
# Display the full website in an iframe
|
| 530 |
html_preview = f"""
|
| 531 |
+
<iframe src="/file=index.html" width="100%" height="600px" style="border:none;"></iframe>
|
| 532 |
+
<p style="text-align: center;"><a href="/file=index.html" target="_blank">View Full Portfolio in New Tab</a></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
"""
|
| 534 |
|
| 535 |
logger.info("Successfully generated portfolio.")
|
| 536 |
+
return html_preview, html_code, None
|
| 537 |
except Exception as e:
|
| 538 |
logger.error(f"Error generating portfolio: {str(e)}")
|
| 539 |
+
return f"Error generating portfolio: {str(e)}", f"Error generating portfolio: {str(e)}", None
|
| 540 |
|
| 541 |
# Gradio Interface
|
| 542 |
with gr.Blocks() as interface:
|
|
|
|
| 547 |
|
| 548 |
html_output = gr.HTML(label="Portfolio Preview")
|
| 549 |
code_output = gr.Textbox(label="Downloadable HTML/CSS Code", lines=10)
|
| 550 |
+
error_output = gr.Textbox(label="Error (if any)", visible=False)
|
| 551 |
|
| 552 |
generate_btn.click(
|
| 553 |
fn=generate_portfolio,
|
| 554 |
inputs=[file_input, theme_input],
|
| 555 |
+
outputs=[html_output, code_output, error_output]
|
| 556 |
)
|
| 557 |
|
| 558 |
interface.launch()
|