Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -209,45 +209,44 @@ def structured_ocr(image_file: Union[str, bytes]) -> str:
|
|
209 |
if temp_path and os.path.exists(temp_path):
|
210 |
os.remove(temp_path)
|
211 |
|
212 |
-
# Gradio Interface
|
213 |
with gr.Blocks(title="Mistral OCR & Structured Output App") as demo:
|
214 |
gr.Markdown("# Mistral OCR & Structured Output App")
|
215 |
gr.Markdown("Extract text from PDFs and images, ask questions about documents, or get structured JSON output!")
|
216 |
|
217 |
with gr.Tab("OCR with PDF URL"):
|
218 |
pdf_url_input = gr.Textbox(label="PDF URL", placeholder="e.g., https://arxiv.org/pdf/2201.04234")
|
219 |
-
pdf_url_output = gr.
|
220 |
pdf_url_button = gr.Button("Process PDF")
|
221 |
pdf_url_button.click(ocr_pdf_url, inputs=pdf_url_input, outputs=pdf_url_output)
|
222 |
|
223 |
with gr.Tab("OCR with Uploaded PDF"):
|
224 |
pdf_file_input = gr.File(label="Upload PDF", file_types=[".pdf"])
|
225 |
-
pdf_file_output = gr.
|
226 |
pdf_file_button = gr.Button("Process Uploaded PDF")
|
227 |
pdf_file_button.click(ocr_uploaded_pdf, inputs=pdf_file_input, outputs=pdf_file_output)
|
228 |
|
229 |
with gr.Tab("OCR with Image URL"):
|
230 |
image_url_input = gr.Textbox(label="Image URL", placeholder="e.g., https://example.com/image.jpg")
|
231 |
-
image_url_output = gr.
|
232 |
image_url_button = gr.Button("Process Image")
|
233 |
image_url_button.click(ocr_image_url, inputs=image_url_input, outputs=image_url_output)
|
234 |
|
235 |
with gr.Tab("OCR with Uploaded Image"):
|
236 |
image_file_input = gr.File(label="Upload Image", file_types=[".jpg", ".png"])
|
237 |
-
image_file_output = gr.
|
238 |
image_file_button = gr.Button("Process Uploaded Image")
|
239 |
image_file_button.click(ocr_uploaded_image, inputs=image_file_input, outputs=image_file_output)
|
240 |
|
241 |
with gr.Tab("Document Understanding"):
|
242 |
doc_url_input = gr.Textbox(label="Document URL", placeholder="e.g., https://arxiv.org/pdf/1805.04770")
|
243 |
question_input = gr.Textbox(label="Question", placeholder="e.g., What is the last sentence?")
|
244 |
-
doc_output = gr.
|
245 |
doc_button = gr.Button("Ask Question")
|
246 |
doc_button.click(document_understanding, inputs=[doc_url_input, question_input], outputs=doc_output)
|
247 |
|
248 |
with gr.Tab("Structured OCR"):
|
249 |
struct_image_input = gr.File(label="Upload Image", file_types=[".jpg", ".png"])
|
250 |
-
struct_output = gr.
|
251 |
struct_button = gr.Button("Get Structured Output")
|
252 |
struct_button.click(structured_ocr, inputs=struct_image_input, outputs=struct_output)
|
253 |
|
|
|
209 |
if temp_path and os.path.exists(temp_path):
|
210 |
os.remove(temp_path)
|
211 |
|
|
|
212 |
with gr.Blocks(title="Mistral OCR & Structured Output App") as demo:
|
213 |
gr.Markdown("# Mistral OCR & Structured Output App")
|
214 |
gr.Markdown("Extract text from PDFs and images, ask questions about documents, or get structured JSON output!")
|
215 |
|
216 |
with gr.Tab("OCR with PDF URL"):
|
217 |
pdf_url_input = gr.Textbox(label="PDF URL", placeholder="e.g., https://arxiv.org/pdf/2201.04234")
|
218 |
+
pdf_url_output = gr.Markdown(label="OCR Result")
|
219 |
pdf_url_button = gr.Button("Process PDF")
|
220 |
pdf_url_button.click(ocr_pdf_url, inputs=pdf_url_input, outputs=pdf_url_output)
|
221 |
|
222 |
with gr.Tab("OCR with Uploaded PDF"):
|
223 |
pdf_file_input = gr.File(label="Upload PDF", file_types=[".pdf"])
|
224 |
+
pdf_file_output = gr.Markdown(label="OCR Result")
|
225 |
pdf_file_button = gr.Button("Process Uploaded PDF")
|
226 |
pdf_file_button.click(ocr_uploaded_pdf, inputs=pdf_file_input, outputs=pdf_file_output)
|
227 |
|
228 |
with gr.Tab("OCR with Image URL"):
|
229 |
image_url_input = gr.Textbox(label="Image URL", placeholder="e.g., https://example.com/image.jpg")
|
230 |
+
image_url_output = gr.Markdown(label="OCR Result")
|
231 |
image_url_button = gr.Button("Process Image")
|
232 |
image_url_button.click(ocr_image_url, inputs=image_url_input, outputs=image_url_output)
|
233 |
|
234 |
with gr.Tab("OCR with Uploaded Image"):
|
235 |
image_file_input = gr.File(label="Upload Image", file_types=[".jpg", ".png"])
|
236 |
+
image_file_output = gr.Markdown(label="OCR Result")
|
237 |
image_file_button = gr.Button("Process Uploaded Image")
|
238 |
image_file_button.click(ocr_uploaded_image, inputs=image_file_input, outputs=image_file_output)
|
239 |
|
240 |
with gr.Tab("Document Understanding"):
|
241 |
doc_url_input = gr.Textbox(label="Document URL", placeholder="e.g., https://arxiv.org/pdf/1805.04770")
|
242 |
question_input = gr.Textbox(label="Question", placeholder="e.g., What is the last sentence?")
|
243 |
+
doc_output = gr.Markdown(label="Answer")
|
244 |
doc_button = gr.Button("Ask Question")
|
245 |
doc_button.click(document_understanding, inputs=[doc_url_input, question_input], outputs=doc_output)
|
246 |
|
247 |
with gr.Tab("Structured OCR"):
|
248 |
struct_image_input = gr.File(label="Upload Image", file_types=[".jpg", ".png"])
|
249 |
+
struct_output = gr.Markdown(label="Structured JSON Output")
|
250 |
struct_button = gr.Button("Get Structured Output")
|
251 |
struct_button.click(structured_ocr, inputs=struct_image_input, outputs=struct_output)
|
252 |
|