Ayesha-Majeed commited on
Commit
f4bdaf1
Β·
verified Β·
1 Parent(s): ccb8d7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -159,29 +159,41 @@ def extract_fields(image):
159
 
160
 
161
  # -------------------- Gradio Interface --------------------
162
- demo = gr.Interface(
163
- fn=extract_fields,
164
- inputs=gr.Image(type="pil", label="Upload Your Document"),
165
- outputs=[
166
- gr.Text(label="Name"),
167
- gr.Text(label="Email"),
168
- gr.Text(label="Phone"),
169
- gr.Text(label="DOB"),
170
- gr.Text(label="Postcode"),
171
- gr.Text(label="Prem (CurBase)"),
172
- gr.Text(label="Temp (Hourly Rate)"),
173
- gr.Textbox(label="Functions", lines=4)
174
- ],
175
- title="Image OCR Field Extractor",
176
- description="Upload a document image to extract structured data fields."
177
- )
178
-
179
- # Create a demo block with example image shown after the interface
180
- with gr.Blocks() as final_ui:
181
- demo.render()
182
- gr.Markdown("### πŸ“Œ Example Document Format (for reference):")
183
- gr.Image(value="example_doc.jpeg", interactive=False, label="Sample Document")
 
 
 
 
 
 
 
 
 
 
 
184
 
185
  if __name__ == "__main__":
186
- final_ui.launch()
 
187
 
 
159
 
160
 
161
  # -------------------- Gradio Interface --------------------
162
+ def extract_fields(image):
163
+ # Your full function definition goes here
164
+ return ["Name", "Email", "Phone", "DOB", "Postcode", "Prem", "Rate", "Functions"]
165
+
166
+ with gr.Blocks() as demo:
167
+ gr.Markdown("## πŸ“„ Image OCR Field Extractor")
168
+ gr.Markdown("Upload a document image to extract structured data fields.")
169
+
170
+ with gr.Row():
171
+ with gr.Column():
172
+ image_input = gr.Image(type="pil", label="πŸ“€ Upload Your Document")
173
+ submit_btn = gr.Button("πŸ” Run Detection")
174
+
175
+ # βœ… One Example Image that auto-fills input when clicked
176
+ gr.Examples(
177
+ examples=["example_doc.jpeg"], # Just one image
178
+ inputs=[image_input],
179
+ label="πŸ“Œ Example Image (Click to load)"
180
+ )
181
+
182
+ with gr.Column():
183
+ name = gr.Text(label="Name")
184
+ email = gr.Text(label="Email")
185
+ phone = gr.Text(label="Phone")
186
+ dob = gr.Text(label="DOB")
187
+ postcode = gr.Text(label="Postcode")
188
+ prem = gr.Text(label="Prem (CurBase)")
189
+ rate = gr.Text(label="Temp (Hourly Rate)")
190
+ functions = gr.Textbox(label="Functions", lines=4)
191
+
192
+ # πŸ” Link button to function
193
+ submit_btn.click(fn=extract_fields, inputs=image_input,
194
+ outputs=[name, email, phone, dob, postcode, prem, rate, functions])
195
 
196
  if __name__ == "__main__":
197
+ demo.launch()
198
+
199