Spaces:
Sleeping
Sleeping
Temporary hiding generate PDF
Browse files
app.py
CHANGED
@@ -2719,19 +2719,20 @@ def create_interface():
|
|
2719 |
results = gr.HTML()
|
2720 |
|
2721 |
# Download button
|
2722 |
-
with gr.Row():
|
2723 |
-
|
2724 |
-
|
2725 |
-
|
2726 |
-
|
2727 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2728 |
|
2729 |
-
pdf_file = gr.File(
|
2730 |
-
label="Download PDF",
|
2731 |
-
visible=False,
|
2732 |
-
interactive=False,
|
2733 |
-
file_types=[".pdf"]
|
2734 |
-
)
|
2735 |
|
2736 |
def process_and_format(file_obj, doc_type_value, template_type_value):
|
2737 |
"""Process document and format results as HTML."""
|
@@ -2762,7 +2763,7 @@ def create_interface():
|
|
2762 |
Please ensure the file is a valid .docx document and try again.
|
2763 |
</div>
|
2764 |
"""
|
2765 |
-
#
|
2766 |
return error_html, gr.update(visible=False), gr.update(visible=False)
|
2767 |
|
2768 |
# Update template type visibility based on document type
|
@@ -2782,29 +2783,32 @@ def create_interface():
|
|
2782 |
submit_btn.click(
|
2783 |
fn=process_and_format,
|
2784 |
inputs=[file_input, doc_type, template_type],
|
2785 |
-
outputs=[results
|
2786 |
)
|
2787 |
|
2788 |
# Function to generate PDF and provide it for download
|
2789 |
-
def generate_pdf(html_content):
|
2790 |
-
|
2791 |
-
|
2792 |
-
|
2793 |
-
|
2794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2795 |
|
2796 |
-
# Return the path to the PDF file
|
2797 |
-
return gr.update(value=tmp_pdf.name, visible=True)
|
2798 |
-
except Exception as e:
|
2799 |
-
logging.error(f"Error generating PDF with WeasyPrint: {str(e)}")
|
2800 |
-
return gr.update(value=None, visible=False)
|
2801 |
|
2802 |
# When the download button is clicked, generate the PDF
|
2803 |
-
download_btn.click(
|
2804 |
-
|
2805 |
-
|
2806 |
-
|
2807 |
-
)
|
|
|
2808 |
|
2809 |
gr.Markdown(
|
2810 |
"""
|
|
|
2719 |
results = gr.HTML()
|
2720 |
|
2721 |
# Download button
|
2722 |
+
# with gr.Row():
|
2723 |
+
# download_btn = gr.Button(
|
2724 |
+
# "⬇️ Download Results as PDF",
|
2725 |
+
# variant="secondary",
|
2726 |
+
# visible=False
|
2727 |
+
# )
|
2728 |
+
#
|
2729 |
+
# pdf_file = gr.File(
|
2730 |
+
# label="Download PDF",
|
2731 |
+
# visible=False,
|
2732 |
+
# interactive=False,
|
2733 |
+
# file_types=[".pdf"]
|
2734 |
+
# )
|
2735 |
|
|
|
|
|
|
|
|
|
|
|
|
|
2736 |
|
2737 |
def process_and_format(file_obj, doc_type_value, template_type_value):
|
2738 |
"""Process document and format results as HTML."""
|
|
|
2763 |
Please ensure the file is a valid .docx document and try again.
|
2764 |
</div>
|
2765 |
"""
|
2766 |
+
# Return only the HTML results
|
2767 |
return error_html, gr.update(visible=False), gr.update(visible=False)
|
2768 |
|
2769 |
# Update template type visibility based on document type
|
|
|
2783 |
submit_btn.click(
|
2784 |
fn=process_and_format,
|
2785 |
inputs=[file_input, doc_type, template_type],
|
2786 |
+
outputs=[results] # Only output the results
|
2787 |
)
|
2788 |
|
2789 |
# Function to generate PDF and provide it for download
|
2790 |
+
# def generate_pdf(html_content):
|
2791 |
+
# try:
|
2792 |
+
# # Use a temporary file to store the PDF
|
2793 |
+
# with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf:
|
2794 |
+
# # Convert HTML to PDF using WeasyPrint
|
2795 |
+
# HTML(string=html_content, base_url='.').write_pdf(tmp_pdf.name)
|
2796 |
+
#
|
2797 |
+
# # Return the path to the PDF file
|
2798 |
+
# return gr.update(value=tmp_pdf.name, visible=True)
|
2799 |
+
# except Exception as e:
|
2800 |
+
# logging.error(f"Error generating PDF with WeasyPrint: {str(e)}")
|
2801 |
+
# traceback.print_exc()
|
2802 |
+
# return gr.update(value=None, visible=False)
|
2803 |
|
|
|
|
|
|
|
|
|
|
|
2804 |
|
2805 |
# When the download button is clicked, generate the PDF
|
2806 |
+
# download_btn.click(
|
2807 |
+
# fn=generate_pdf,
|
2808 |
+
# inputs=[results],
|
2809 |
+
# outputs=[pdf_file]
|
2810 |
+
# )
|
2811 |
+
|
2812 |
|
2813 |
gr.Markdown(
|
2814 |
"""
|