Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
from fastapi.responses import JSONResponse
|
| 3 |
-
import uvicorn, os, tempfile
|
| 4 |
from pipeline import extract_text_from_pdf, extract_key_values_with_gemini
|
| 5 |
|
| 6 |
-
app = FastAPI(title="AutoFill Form Extractor API")
|
| 7 |
-
|
| 8 |
FIELDS = [
|
| 9 |
"Name", "DOB", "Gender", "FatherName", "MotherName",
|
| 10 |
"Address", "City", "State", "Pincode", "Mobile", "Email",
|
|
@@ -12,24 +8,16 @@ FIELDS = [
|
|
| 12 |
"IssueDate", "ExpiryDate"
|
| 13 |
]
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
tmp.write(await file.read())
|
| 21 |
-
tmp_path = tmp.name
|
| 22 |
-
|
| 23 |
-
text = extract_text_from_pdf(tmp_path)
|
| 24 |
-
result = extract_key_values_with_gemini(text, fields=FIELDS)
|
| 25 |
-
|
| 26 |
-
return JSONResponse(content={"success": True, "data": result})
|
| 27 |
-
except Exception as e:
|
| 28 |
-
return JSONResponse(content={"success": False, "error": str(e)})
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from pipeline import extract_text_from_pdf, extract_key_values_with_gemini
|
| 3 |
|
|
|
|
|
|
|
| 4 |
FIELDS = [
|
| 5 |
"Name", "DOB", "Gender", "FatherName", "MotherName",
|
| 6 |
"Address", "City", "State", "Pincode", "Mobile", "Email",
|
|
|
|
| 8 |
"IssueDate", "ExpiryDate"
|
| 9 |
]
|
| 10 |
|
| 11 |
+
def process_pdf(file):
|
| 12 |
+
if not file:
|
| 13 |
+
return {"error": "No file uploaded."}
|
| 14 |
+
text = extract_text_from_pdf(file.name)
|
| 15 |
+
return extract_key_values_with_gemini(text, FIELDS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
with gr.Blocks() as demo:
|
| 18 |
+
gr.Markdown("## AutoForm Extractor")
|
| 19 |
+
file_input = gr.File(label="Upload PDF")
|
| 20 |
+
output = gr.JSON()
|
| 21 |
+
file_input.change(process_pdf, file_input, output)
|
| 22 |
|
| 23 |
+
demo.launch()
|
|
|