Upload 2 files
Browse files
key.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "service_account",
|
| 3 |
+
"project_id": "shawarma-375cb",
|
| 4 |
+
"private_key_id": "a78e23af470a167de009cf9d5ae2ff94da1f0af1",
|
| 5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDO1SrxHqupMBCB\naw/CNhB2QpWp0xP50lqZYnVSH0ZTVkNDbqECmSE11360JSXmhifl4xy3lssn486m\n1rafc+7pflTv8OP0TCbyHMlvh7lr1dFAXE1qtjGeQfUvQmP550qfZSE1f6cCe6dH\nO8SwkNFhH4HifWsu6m4nz54OJn9NfBjGYKQX9T7Kdqsrlf+NuwaEmJVNmz3wZEnY\nYnILx1a13ba3QKtFPgMfLkIOrhx32XYwdDEm2J16u8v55+ZD1GGE0B+wu/a8u5te\nQxkd4bLAhr36GewAk93Y2YRpEcU1jkK9J2Zb5pK+5r8iDN+tJipY+EizM+gI0iMd\nt7BQ4xCbAgMBAAECggEAFy6iUQM4h06JUxAeZIytvKuK3c14PDR9DhsQfkNeHQIa\nqOix6DoklEXSgDt3q4ZW23fgpJ0kqRRp+Z4wOuACI66Ss5AC5MNSTCm41CTYvgLp\noLaXwMGp/wxygDkHPp/TZ9ksZzQnEmqsnZnP2mBo72NaKfoXtNr2vMSS+RAMjbEK\n+D6J3ztd/bSoizhWS1g+V0KShGoduDhJ9qukav85s7/qWSjziCucmIJaqcykqv+j\nz6DQdgFr9NiCTZ0yPlOR20cvci6m/Cu+gw1BDp+HsIZ++0YMYb5dvmZANADycn1I\nXAwbJFaxrt76KDpOW3+FW2iLULT8BGEIO1p3GhUxYQKBgQDqo0sXLKED2hqdqI+C\nB2zINkwS8uSrbuh+ZF9SN9wc1d4H4iEPf52Kniqxacz/I/s9HMOVSV70wbQmi3jF\nTqI7vl1jaBe4PKqYCRsadH1tjTSnq9x99+DR4jBl9A9z4scb5YGAzfPlEv8W2aK0\nrjVD0MeK6lfogKGbjpV9y+NhoQKBgQDhqdGjgsjIU/WU03vRDom16lBH6MMmH8Kk\nFw9oBHG6RJfFPT+lxSJITOm79XZU1zqsLmqbYizvcbDGNGgg7BJFCsXLsVBeZTSf\n6LmDMBsxmD5TgzIHLX5jDC5007rFDJjOB6OxyOwJ2dDdF8N9ITQ8+6f1sdjajz7H\nox0ps1LAuwKBgQDPMu3vhACYFzTjvmMj7wyX7KLXJNjbrm/ulRI714oviIiuK3kI\nZ6gmLbADxSs6r3qAJ/Nq1ETfHGLKmuVGTz8iROPREa3IiwIWigv+G5pbcJNr8W8f\nahKFJRmaHqC6tCshrlTi+nwC8PiEJCHzLddpkGd1e6Wvck/Dv3Cxiqe7oQKBgB0r\nDRzcb8VtDMYy28M25NfttHjG/kp0On1pOaWRRX31FcT52Ls9kuPThTa1UJlAxKWy\nzjbNZs+AW4ATEA6JVQc1kEF25tN8s2Oj+i6ZzjoH2q6Cu7mvyLFWxr51C6Qir7GZ\nzS/Sr6fKTrP1OWB4JT9oq9oXJdeCQnQdgkx8kEq3AoGBAMnlTzZwL2tdBCrkdMIc\nuqsTqsATp/hz6GT/xGYW2rc1mf1G0iyOZTukN47Xy8m1Eee5cf+DX9U0+wsmU1P1\nHgr0StfpVybuD6xc/W9gIDLrINwUjMuVUvX5+vS9vndcqdWo4KLue0aN1nt9Hlye\nGfW8qP++y4uHIxeD8bp8Jf55\n-----END PRIVATE KEY-----\n",
|
| 6 |
+
"client_email": "firebase-adminsdk-2v1g7@shawarma-375cb.iam.gserviceaccount.com",
|
| 7 |
+
"client_id": "109223466657132126008",
|
| 8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-2v1g7%40shawarma-375cb.iam.gserviceaccount.com",
|
| 12 |
+
"universe_domain": "googleapis.com"
|
| 13 |
+
}
|
side.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import firebase_admin
|
| 3 |
+
from firebase_admin import credentials, firestore
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
# Firebase Admin SDK initialization
|
| 7 |
+
cred = credentials.Certificate("key.json") # Replace with your Firebase service account key file
|
| 8 |
+
firebase_admin.initialize_app(cred)
|
| 9 |
+
db = firestore.client()
|
| 10 |
+
|
| 11 |
+
# Function to get orders from Firestore and calculate totals
|
| 12 |
+
def fetch_orders():
|
| 13 |
+
# Fetch orders from Firestore
|
| 14 |
+
orders = db.collection("orders").get()
|
| 15 |
+
|
| 16 |
+
# Initialize variables to hold display data and grand total
|
| 17 |
+
orders_display = []
|
| 18 |
+
grand_total = 0
|
| 19 |
+
|
| 20 |
+
# Iterate through each order to extract relevant information
|
| 21 |
+
for order in orders:
|
| 22 |
+
order_data = order.to_dict()
|
| 23 |
+
name = order_data.get("name")
|
| 24 |
+
phone = order_data.get("phone", "N/A")
|
| 25 |
+
hostel = order_data.get("hostel_name", "N/A") # Fetch hostel information
|
| 26 |
+
items = order_data.get("items", [])
|
| 27 |
+
|
| 28 |
+
# Ensure items is a list of dictionaries
|
| 29 |
+
if not isinstance(items, list):
|
| 30 |
+
items = [] # Default to an empty list if items is not in the correct format
|
| 31 |
+
|
| 32 |
+
# Calculate total for each individual order
|
| 33 |
+
total_price = order_data.get("total_price", 0)
|
| 34 |
+
grand_total += total_price
|
| 35 |
+
|
| 36 |
+
# Append each item as a separate row
|
| 37 |
+
for item in items:
|
| 38 |
+
if isinstance(item, dict):
|
| 39 |
+
category = item.get("category", "")
|
| 40 |
+
item_name = item.get("item", "")
|
| 41 |
+
quantity = item.get("quantity", 0)
|
| 42 |
+
price = item.get("price", 0)
|
| 43 |
+
orders_display.append([name, phone, hostel, category, item_name, quantity, price])
|
| 44 |
+
# Clear name, phone, and hostel for subsequent items for a cleaner look
|
| 45 |
+
name, phone, hostel = "", "", ""
|
| 46 |
+
|
| 47 |
+
# Append a subtotal row after all items for the current person
|
| 48 |
+
orders_display.append(["", "", "", "", "Subtotal", "", total_price])
|
| 49 |
+
|
| 50 |
+
# Append a grand total row at the end
|
| 51 |
+
orders_display.append(["", "", "", "", "Grand Total", "", grand_total])
|
| 52 |
+
|
| 53 |
+
return orders_display
|
| 54 |
+
|
| 55 |
+
# Gradio Interface
|
| 56 |
+
def gradio_display_interface():
|
| 57 |
+
with gr.Blocks() as demo:
|
| 58 |
+
# Display section for individual order totals with headers
|
| 59 |
+
gr.Markdown("### ADMIN PANEL")
|
| 60 |
+
orders_display = gr.Dataframe(value=[], headers=["Name", "Phone", "Hostel", "Category", "Item", "Quantity", "Price"], interactive=False, wrap=True)
|
| 61 |
+
|
| 62 |
+
# Fetch and display the orders when the button is clicked
|
| 63 |
+
fetch_button = gr.Button("Fetch Orders")
|
| 64 |
+
fetch_button.click(
|
| 65 |
+
fn=fetch_orders,
|
| 66 |
+
inputs=[],
|
| 67 |
+
outputs=[orders_display]
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
return demo
|
| 71 |
+
|
| 72 |
+
# Run the Gradio app
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
gradio_display_interface().launch()
|