Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -146,17 +146,30 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
| 146 |
with gr.Tabs():
|
| 147 |
with gr.Tab("π Upload File"):
|
| 148 |
file_input = gr.File(label="Upload Document", file_types=[".pdf", ".docx", ".png", ".jpg", ".jpeg"])
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
report_box = gr.Textbox(label="Verification Report", lines=20, elem_id="report-box")
|
| 151 |
verify_btn_file = gr.Button("π Verify Document")
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
with gr.Tab("π Paste Text"):
|
| 155 |
text_input = gr.Textbox(label="Paste Notification Text", lines=10, placeholder="Paste text here...")
|
| 156 |
-
|
| 157 |
report_box_text = gr.Textbox(label="Verification Report", lines=20, elem_id="report-box")
|
| 158 |
verify_btn_text = gr.Button("π Verify Text")
|
| 159 |
-
|
|
|
|
| 160 |
|
| 161 |
# ------------------------
|
| 162 |
# Launch
|
|
|
|
| 146 |
with gr.Tabs():
|
| 147 |
with gr.Tab("π Upload File"):
|
| 148 |
file_input = gr.File(label="Upload Document", file_types=[".pdf", ".docx", ".png", ".jpg", ".jpeg"])
|
| 149 |
+
|
| 150 |
+
# Use both preview options: one for text, one for image
|
| 151 |
+
preview_text = gr.Textbox(label="π File/Text Preview", lines=10, elem_id="preview-box")
|
| 152 |
+
preview_image = gr.Image(label="πΌοΈ Image Preview", elem_id="preview-box")
|
| 153 |
+
|
| 154 |
report_box = gr.Textbox(label="Verification Report", lines=20, elem_id="report-box")
|
| 155 |
verify_btn_file = gr.Button("π Verify Document")
|
| 156 |
+
|
| 157 |
+
def handle_file(file):
|
| 158 |
+
preview, report = verify_document(file)
|
| 159 |
+
if isinstance(preview, Image.Image): # image case
|
| 160 |
+
return None, preview, report
|
| 161 |
+
else: # text case
|
| 162 |
+
return preview, None, report
|
| 163 |
+
|
| 164 |
+
verify_btn_file.click(fn=handle_file, inputs=file_input, outputs=[preview_text, preview_image, report_box])
|
| 165 |
|
| 166 |
with gr.Tab("π Paste Text"):
|
| 167 |
text_input = gr.Textbox(label="Paste Notification Text", lines=10, placeholder="Paste text here...")
|
| 168 |
+
preview_text2 = gr.Textbox(label="Text Preview", lines=10, elem_id="preview-box")
|
| 169 |
report_box_text = gr.Textbox(label="Verification Report", lines=20, elem_id="report-box")
|
| 170 |
verify_btn_text = gr.Button("π Verify Text")
|
| 171 |
+
|
| 172 |
+
verify_btn_text.click(fn=process_text_input, inputs=text_input, outputs=[preview_text2, report_box_text])
|
| 173 |
|
| 174 |
# ------------------------
|
| 175 |
# Launch
|