Ayush soni commited on
Commit
9cdbbd4
·
1 Parent(s): e98e646
Files changed (1) hide show
  1. app.py +84 -13
app.py CHANGED
@@ -18,21 +18,92 @@ def process_invoice(file_bytes):
18
  json_data = generate_json_from_text(raw_text)
19
  return raw_text, json_data
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
 
 
 
 
 
 
 
 
 
22
 
23
- ### Gradio UI
24
- with gr.Blocks() as demo:
25
- gr.Markdown("# 🧾 Invoice Processing App")
26
- gr.Markdown("Upload an invoice image. The app extracts **OCR text** and generates **structured JSON**.")
27
-
28
- with gr.Row():
29
- input_file = gr.File(label="Upload Invoice Image", type="binary", file_types=[".png", ".jpg", ".jpeg"])
 
 
 
 
 
 
30
 
31
- with gr.Row():
32
- raw_text_output = gr.Textbox(label="Extracted OCR Text", lines=10)
33
- json_output = gr.JSON(label="Structured JSON")
34
-
35
- process_btn = gr.Button("Process Invoice")
 
 
 
 
 
 
 
 
36
 
37
  process_btn.click(
38
  process_invoice,
@@ -40,4 +111,4 @@ with gr.Blocks() as demo:
40
  outputs=[raw_text_output, json_output]
41
  )
42
 
43
- demo.launch()
 
18
  json_data = generate_json_from_text(raw_text)
19
  return raw_text, json_data
20
 
21
+ # Custom CSS with Tailwind CDN
22
+ custom_css = """
23
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
24
+ body {
25
+ font-family: 'Inter', sans-serif;
26
+ background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
27
+ }
28
+ .gradio-container {
29
+ max-width: 1200px;
30
+ margin: 0 auto;
31
+ padding: 2rem;
32
+ }
33
+ h1 {
34
+ font-size: 2.5rem;
35
+ font-weight: 700;
36
+ color: #1f2937;
37
+ text-align: center;
38
+ margin-bottom: 1rem;
39
+ }
40
+ h3 {
41
+ font-size: 1.25rem;
42
+ color: #4b5563;
43
+ text-align: center;
44
+ margin-bottom: 2rem;
45
+ }
46
+ .gr-button {
47
+ background-color: #2563eb;
48
+ color: white;
49
+ padding: 0.75rem 1.5rem;
50
+ border-radius: 0.5rem;
51
+ font-weight: 600;
52
+ transition: background-color 0.3s ease;
53
+ }
54
+ .gr-button:hover {
55
+ background-color: #1e40af;
56
+ }
57
+ .gr-textbox, .gr-json {
58
+ border-radius: 0.5rem;
59
+ border: 1px solid #d1d5db;
60
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
61
+ }
62
+ .gr-file-upload {
63
+ border: 2px dashed #d1d5db;
64
+ border-radius: 0.5rem;
65
+ padding: 1rem;
66
+ background-color: white;
67
+ }
68
+ """
69
 
70
+ # Gradio UI
71
+ with gr.Blocks(css=custom_css) as demo:
72
+ gr.Markdown(
73
+ """
74
+ # 🧾 Invoice Processing App
75
+ Upload an invoice image to extract **OCR text** and generate **structured JSON** output.
76
+ """,
77
+ elem_classes="text-center"
78
+ )
79
 
80
+ with gr.Row(variant="panel"):
81
+ with gr.Column(scale=1):
82
+ input_file = gr.File(
83
+ label="Upload Invoice Image",
84
+ type="binary",
85
+ file_types=[".png", ".jpg", ".jpeg"],
86
+ elem_classes="gr-file-upload"
87
+ )
88
+ process_btn = gr.Button(
89
+ "Process Invoice",
90
+ variant="primary",
91
+ elem_classes="gr-button mt-4 w-full"
92
+ )
93
 
94
+ with gr.Row(variant="panel"):
95
+ with gr.Column(scale=1):
96
+ raw_text_output = gr.Textbox(
97
+ label="Extracted OCR Text",
98
+ lines=10,
99
+ placeholder="Extracted text will appear here...",
100
+ elem_classes="gr-textbox"
101
+ )
102
+ with gr.Column(scale=1):
103
+ json_output = gr.JSON(
104
+ label="Structured JSON",
105
+ elem_classes="gr-json"
106
+ )
107
 
108
  process_btn.click(
109
  process_invoice,
 
111
  outputs=[raw_text_output, json_output]
112
  )
113
 
114
+ demo.launch()