sujataprakashdatycs commited on
Commit
722bccb
·
verified ·
1 Parent(s): 6bf1452

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -104,6 +104,14 @@ def load_sample_pdf():
104
  return SAMPLE_PDF
105
 
106
 
 
 
 
 
 
 
 
 
107
  # ---------- Gradio UI ----------
108
  with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
109
  gr.HTML(f"""
@@ -124,7 +132,7 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
124
 
125
  # Right Side (Preview + Output)
126
  with gr.Column(scale=2):
127
- pdf_preview = gr.File(label="📑 Preview Uploaded PDF", interactive=False)
128
  output_md = gr.Markdown(
129
  label="Validation Report",
130
  value="<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>📄 Upload a PDF and click <b>Run Validation</b> to start.</div>",
@@ -133,7 +141,7 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
133
  # ---------- Button Events ----------
134
  # Sample PDF click
135
  sample_btn.click(
136
- fn=lambda: (load_sample_pdf(), load_sample_pdf()),
137
  inputs=[],
138
  outputs=[pdf_upload, pdf_preview]
139
  )
@@ -147,7 +155,7 @@ with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
147
 
148
  # Preview PDF when uploaded
149
  pdf_upload.change(
150
- fn=lambda f: f.name if f else None,
151
  inputs=pdf_upload,
152
  outputs=pdf_preview
153
  )
@@ -167,12 +175,6 @@ if __name__ == "__main__":
167
 
168
 
169
 
170
-
171
-
172
-
173
-
174
-
175
-
176
  # import os
177
  # import gradio as gr
178
  # import json
 
104
  return SAMPLE_PDF
105
 
106
 
107
+ # ---------- Helper: PDF Preview ----------
108
+ def preview_pdf(file):
109
+ if file is None:
110
+ return "<div style='color:gray;'>No PDF uploaded</div>"
111
+ path = file.name if hasattr(file, "name") else file
112
+ return f'<iframe src="{path}" width="100%" height="600px"></iframe>'
113
+
114
+
115
  # ---------- Gradio UI ----------
116
  with gr.Blocks(theme=simple_theme, title=APP_TITLE) as interface:
117
  gr.HTML(f"""
 
132
 
133
  # Right Side (Preview + Output)
134
  with gr.Column(scale=2):
135
+ pdf_preview = gr.HTML(label="📑 PDF Preview")
136
  output_md = gr.Markdown(
137
  label="Validation Report",
138
  value="<div style='border:2px solid #1e40af; border-radius:12px; padding:15px; background-color:#f0f9ff;'>📄 Upload a PDF and click <b>Run Validation</b> to start.</div>",
 
141
  # ---------- Button Events ----------
142
  # Sample PDF click
143
  sample_btn.click(
144
+ fn=lambda: (load_sample_pdf(), preview_pdf(load_sample_pdf())),
145
  inputs=[],
146
  outputs=[pdf_upload, pdf_preview]
147
  )
 
155
 
156
  # Preview PDF when uploaded
157
  pdf_upload.change(
158
+ fn=preview_pdf,
159
  inputs=pdf_upload,
160
  outputs=pdf_preview
161
  )
 
175
 
176
 
177
 
 
 
 
 
 
 
178
  # import os
179
  # import gradio as gr
180
  # import json