joschetan commited on
Commit
4e3a0fd
·
verified ·
1 Parent(s): e195f58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -28
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  import pandas as pd
3
  import requests
4
  import json
5
- import openpyxl
6
  import pdfplumber
7
  import re
8
  import spaces
@@ -35,11 +34,11 @@ def verify_password(pwd):
35
 
36
  def verify_admin(pwd):
37
  if pwd == "TEST":
38
- return "✅ Admin Mode Unlocked Successfully!"
39
  else:
40
- return "❌ Galat Admin Password!"
41
 
42
- # Custom CSS matching your exact Streamlit styling
43
  custom_css = """
44
  .creator-card {
45
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
@@ -68,7 +67,7 @@ custom_css = """
68
 
69
  with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
70
 
71
- # 🔒 1. Global Password Lock Screen
72
  with gr.Column(visible=True) as login_screen:
73
  with gr.Row():
74
  gr.Column(scale=1)
@@ -79,19 +78,17 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
79
  unlock_btn = gr.Button("Unlock App", variant="primary")
80
  gr.Column(scale=1)
81
 
82
- # 🚀 2. Main Application Layout (Identical to Streamlit Sidebar Style)
83
  with gr.Column(visible=False) as main_app:
84
  with gr.Row():
85
 
86
- # 📌 Left Sidebar Column (Photo, Profile Card, Metrics, w.e.f & Rate PDF Uploader)
87
- with gr.Column(scale=1, min_width=300):
88
- # 1. Photo
89
  try:
90
  gr.Image("ck_photo.jpg", show_label=False, interactive=False)
91
  except:
92
  gr.Markdown("*(Chetan Joshi Photo)*")
93
 
94
- # 2. Blue Profile Card
95
  gr.HTML("""
96
  <div class="creator-card">
97
  <div class="creator-name">Chetan Joshi</div>
@@ -104,13 +101,11 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
104
  </div>
105
  """)
106
 
107
- # 3. Currency Metrics Row
108
  with gr.Row():
109
  gr.Number(value=109.8, label="EUR", interactive=False)
110
  gr.Number(value=128.15, label="GBP", interactive=False)
111
  gr.Number(value=94.8, label="USD", interactive=False)
112
 
113
- # 4. w.e.f Date Display Box
114
  gr.HTML("<div style='text-align: center; margin-top: 10px; margin-bottom: 12px;'><span style='font-size: 16px; font-weight: 800; color: #00cec9; background: rgba(0, 206, 201, 0.1); padding: 6px 12px; border-radius: 6px; display: inline-block;'>📅 w.e.f: N/A</span></div>")
115
 
116
  gr.Markdown("---")
@@ -119,30 +114,60 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
119
  rate_output = gr.Textbox(label="Status", interactive=False)
120
  pdf_rate_input.change(fn=process_rate_pdf, inputs=pdf_rate_input, outputs=rate_output)
121
 
122
- # 📌 Right Main Dashboard Column
123
  with gr.Column(scale=3):
124
  gr.Markdown("# 🚢 CK Export Invoice Processor")
125
  gr.Markdown("---")
126
 
127
- with gr.Tabs():
128
- # Tab 1: Invoice Processor Zone
129
- with gr.TabItem("📄 Invoice Processing Zone"):
130
- gr.Markdown("### Invoicing PDF ya Excel ke sath-sath GST Invoice aur DEEC Declaration upload karne ka zhon.")
131
- shipper_dropdown = gr.Dropdown(choices=["Shipper 1", "Shipper 2"], label="Kis shipper ka invoice process karna hai?")
132
- job_file = gr.File(label="Upload Job Excel Format File")
133
- process_btn = gr.Button("Process Invoice & Generate Excel", variant="primary")
134
- output_status = gr.Textbox(label="Processing Result")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
- # Tab 2: Admin Settings Access
137
- with gr.TabItem("🛠️ Admin Settings Access"):
138
- gr.Markdown("### Admin Mode Access")
139
- admin_pwd = gr.Textbox(label="Admin password darj karein:", type="password")
140
- admin_login_btn = gr.Button("Login to Admin")
141
- admin_output = gr.Textbox(label="Admin Status", interactive=False)
142
- admin_login_btn.click(fn=verify_admin, inputs=admin_pwd, outputs=admin_output)
 
 
 
 
143
 
 
144
  unlock_btn.click(fn=verify_password, inputs=pass_input, outputs=[login_screen, main_app])
145
  pass_input.submit(fn=verify_password, inputs=pass_input, outputs=[login_screen, main_app])
 
 
 
 
 
 
 
 
 
 
146
 
147
  if __name__ == "__main__":
148
  demo.launch()
 
2
  import pandas as pd
3
  import requests
4
  import json
 
5
  import pdfplumber
6
  import re
7
  import spaces
 
34
 
35
  def verify_admin(pwd):
36
  if pwd == "TEST":
37
+ return gr.update(visible=False), gr.update(visible=True) # Login screen hide, Admin Panel show
38
  else:
39
+ return gr.update(visible=True), gr.update(visible=False)
40
 
41
+ # Custom CSS for exact Streamlit matching style
42
  custom_css = """
43
  .creator-card {
44
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
 
67
 
68
  with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
69
 
70
+ # 🔒 1. Global Password Lock Screen (Password: CKJ)
71
  with gr.Column(visible=True) as login_screen:
72
  with gr.Row():
73
  gr.Column(scale=1)
 
78
  unlock_btn = gr.Button("Unlock App", variant="primary")
79
  gr.Column(scale=1)
80
 
81
+ # 🚀 2. Main Application Layout
82
  with gr.Column(visible=False) as main_app:
83
  with gr.Row():
84
 
85
+ # 📌 Left Sidebar (Photo, Blue Card, Metrics, w.e.f & Rate PDF Uploader)
86
+ with gr.Column(scale=1, min_width=320):
 
87
  try:
88
  gr.Image("ck_photo.jpg", show_label=False, interactive=False)
89
  except:
90
  gr.Markdown("*(Chetan Joshi Photo)*")
91
 
 
92
  gr.HTML("""
93
  <div class="creator-card">
94
  <div class="creator-name">Chetan Joshi</div>
 
101
  </div>
102
  """)
103
 
 
104
  with gr.Row():
105
  gr.Number(value=109.8, label="EUR", interactive=False)
106
  gr.Number(value=128.15, label="GBP", interactive=False)
107
  gr.Number(value=94.8, label="USD", interactive=False)
108
 
 
109
  gr.HTML("<div style='text-align: center; margin-top: 10px; margin-bottom: 12px;'><span style='font-size: 16px; font-weight: 800; color: #00cec9; background: rgba(0, 206, 201, 0.1); padding: 6px 12px; border-radius: 6px; display: inline-block;'>📅 w.e.f: N/A</span></div>")
110
 
111
  gr.Markdown("---")
 
114
  rate_output = gr.Textbox(label="Status", interactive=False)
115
  pdf_rate_input.change(fn=process_rate_pdf, inputs=pdf_rate_input, outputs=rate_output)
116
 
117
+ # 📌 Right Main Dashboard
118
  with gr.Column(scale=3):
119
  gr.Markdown("# 🚢 CK Export Invoice Processor")
120
  gr.Markdown("---")
121
 
122
+ # Normal User View / Processor Zone
123
+ with gr.Column(visible=True) as user_dashboard:
124
+ gr.Markdown("### 📄 Invoice Processing Zone (Multi-Document)")
125
+ gr.Markdown("इनवॉइस PDF या Excel के साथ-साथ GST Invoice और DEEC Declaration अपलोड करने और पर्टिकुलर सेल/कॉलम में भेजने का ज़ोन।")
126
+
127
+ # Shipper Dropdown (Jo gayab ho gaya tha)
128
+ shipper_dropdown = gr.Dropdown(
129
+ choices=["Welspun India", "Reliance Industries", "Adani Enterprises", "Default Shipper"],
130
+ label="किस शिपर का इनवॉइस प्रोसेस करना है?",
131
+ interactive=True
132
+ )
133
+
134
+ job_file = gr.File(label="Upload Job Excel Format File")
135
+ process_btn = gr.Button("Process Invoice & Generate Excel", variant="primary")
136
+ output_status = gr.Textbox(label="Processing Result")
137
+
138
+ gr.Markdown("---")
139
+
140
+ # Admin Login Expander/Section inside User Dashboard
141
+ with gr.Accordion("🛠️ Admin Settings Access", open=False):
142
+ admin_pwd_input = gr.Textbox(label="Admin password darj karein:", type="password")
143
+ admin_login_btn = gr.Button("Login Karein")
144
+ admin_login_msg = gr.Markdown()
145
 
146
+ # Admin Mode View (Initially Hidden)
147
+ with gr.Column(visible=False) as admin_dashboard:
148
+ gr.Markdown("# 🛠️ CK Export Processor - Admin Mode")
149
+ admin_back_btn = gr.Button("🚪 Log Out Admin", variant="secondary")
150
+
151
+ admin_tabs = gr.Radio(
152
+ ["i. 🏢 Add Shipper Name & Setup", "iii. 🌍 Global Masters & Common Dictionaries"],
153
+ label="📋 Admin settings chunein:",
154
+ value="i. 🏢 Add Shipper Name & Setup"
155
+ )
156
+ admin_content_box = gr.Markdown("Admin features and settings will appear here.")
157
 
158
+ # Event Bindings
159
  unlock_btn.click(fn=verify_password, inputs=pass_input, outputs=[login_screen, main_app])
160
  pass_input.submit(fn=verify_password, inputs=pass_input, outputs=[login_screen, main_app])
161
+
162
+ # Admin Login Switch inside User Dashboard
163
+ def handle_admin_login(pwd):
164
+ if pwd == "TEST":
165
+ return gr.update(visible=False), gr.update(visible=True)
166
+ else:
167
+ return gr.update(visible=True), gr.update(visible=False)
168
+
169
+ admin_login_btn.click(fn=handle_admin_login, inputs=admin_pwd_input, outputs=[user_dashboard, admin_dashboard])
170
+ admin_back_btn.click(fn=lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[user_dashboard, admin_dashboard])
171
 
172
  if __name__ == "__main__":
173
  demo.launch()