Spaces:
Sleeping
Sleeping
Update app.py (#13)
Browse files- Update app.py (63dc035f8eb15001d8587f62ad094734163ed575)
app.py
CHANGED
|
@@ -1,8 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import random
|
| 4 |
-
import string
|
| 5 |
-
import json
|
| 6 |
|
| 7 |
# Dummy storage for balance display (real balance managed on backend)
|
| 8 |
mock_balance = 0.0
|
|
@@ -10,15 +7,11 @@ mock_balance = 0.0
|
|
| 10 |
# Backend server URL (replace with your private server for real transactions)
|
| 11 |
BACKEND_URL = "http://your-private-server:5000" # Update with actual server address
|
| 12 |
|
| 13 |
-
# Function to generate random account IDs for display purposes
|
| 14 |
-
def generate_account_id():
|
| 15 |
-
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
|
| 16 |
-
|
| 17 |
# Function to connect to backend for balance update or retrieval
|
| 18 |
-
def fetch_balance(
|
| 19 |
global mock_balance
|
| 20 |
try:
|
| 21 |
-
response = requests.
|
| 22 |
if response.status_code == 200:
|
| 23 |
data = response.json()
|
| 24 |
mock_balance = data.get("balance", 0.0)
|
|
@@ -29,14 +22,14 @@ def fetch_balance(email, password):
|
|
| 29 |
return f"Backend connection failed: {str(e)} (Using mock balance)", mock_balance
|
| 30 |
|
| 31 |
# Function for placement stage (deposit real funds)
|
| 32 |
-
def process_deposit(
|
| 33 |
global mock_balance
|
| 34 |
try:
|
| 35 |
amount = float(deposit_amount)
|
| 36 |
if amount <= 0:
|
| 37 |
return "Deposit amount must be positive.", mock_balance
|
| 38 |
response = requests.post(f"{BACKEND_URL}/deposit", json={
|
| 39 |
-
"
|
| 40 |
})
|
| 41 |
if response.status_code == 200:
|
| 42 |
data = response.json()
|
|
@@ -49,37 +42,16 @@ def process_deposit(email, password, deposit_amount, source_label="Unknown Sourc
|
|
| 49 |
except Exception as e:
|
| 50 |
return f"Error: {str(e)} (Backend not reachable)", mock_balance
|
| 51 |
|
| 52 |
-
# Function for
|
| 53 |
-
def
|
| 54 |
-
global mock_balance
|
| 55 |
-
try:
|
| 56 |
-
amount = float(transfer_amount)
|
| 57 |
-
if amount <= 0:
|
| 58 |
-
return "Invalid transfer amount.", mock_balance
|
| 59 |
-
response = requests.post(f"{BACKEND_URL}/layer", json={
|
| 60 |
-
"email": email, "password": password, "amount": amount, "layers": num_layers
|
| 61 |
-
})
|
| 62 |
-
if response.status_code == 200:
|
| 63 |
-
data = response.json()
|
| 64 |
-
mock_balance = data.get("balance", mock_balance)
|
| 65 |
-
return data.get("message", f"Transferred ${amount:,.2f} through layers"), mock_balance
|
| 66 |
-
else:
|
| 67 |
-
return f"Layering failed: {response.text}", mock_balance
|
| 68 |
-
except ValueError:
|
| 69 |
-
return "Invalid transfer amount. Enter a number.", mock_balance
|
| 70 |
-
except Exception as e:
|
| 71 |
-
return f"Error: {str(e)} (Backend not reachable)", mock_balance
|
| 72 |
-
|
| 73 |
-
# Function for integration stage (withdraw to destination)
|
| 74 |
-
def process_withdrawal(email, password, withdraw_amount, card_type, card_number, expiry, cvv):
|
| 75 |
global mock_balance
|
| 76 |
try:
|
| 77 |
amount = float(withdraw_amount)
|
| 78 |
if amount <= 0:
|
| 79 |
return "Invalid withdrawal amount.", mock_balance
|
| 80 |
response = requests.post(f"{BACKEND_URL}/withdraw", json={
|
| 81 |
-
"
|
| 82 |
-
"
|
| 83 |
})
|
| 84 |
if response.status_code == 200:
|
| 85 |
data = response.json()
|
|
@@ -114,20 +86,12 @@ custom_css = """
|
|
| 114 |
font-size: 28px;
|
| 115 |
margin: 20px 0;
|
| 116 |
}
|
| 117 |
-
.buttons {
|
| 118 |
-
display: flex;
|
| 119 |
-
justify-content: center;
|
| 120 |
-
gap: 20px;
|
| 121 |
-
margin-top: 20px;
|
| 122 |
-
}
|
| 123 |
button {
|
| 124 |
background-color: #ff66b2 !important;
|
| 125 |
color: white !important;
|
| 126 |
-
border: none !important;
|
| 127 |
padding: 10px 20px !important;
|
| 128 |
font-size: 16px !important;
|
| 129 |
border-radius: 5px !important;
|
| 130 |
-
cursor: pointer !important;
|
| 131 |
}
|
| 132 |
button:hover {
|
| 133 |
background-color: #ff3399 !important;
|
|
@@ -143,73 +107,39 @@ input {
|
|
| 143 |
}
|
| 144 |
"""
|
| 145 |
|
| 146 |
-
# Define the
|
| 147 |
with gr.Blocks(css=custom_css) as demo:
|
| 148 |
-
gr.Markdown("<div class='header'>Pink
|
| 149 |
-
|
| 150 |
-
# Authentication inputs
|
| 151 |
-
with gr.Column():
|
| 152 |
-
email_input = gr.Textbox(placeholder="Enter Cash App Email", label="Cash App Email")
|
| 153 |
-
password_input = gr.Textbox(placeholder="Enter Cash App Password", label="Cash App Password", type="password")
|
| 154 |
-
login_btn = gr.Button("Connect to System")
|
| 155 |
-
status_output = gr.Textbox(value="Not connected", label="Transaction Log", interactive=False, lines=10)
|
| 156 |
|
| 157 |
# Balance display
|
| 158 |
with gr.Column(elem_classes="balance-box"):
|
| 159 |
balance_output = gr.Textbox(value="$0.00", label="Current Balance", interactive=False)
|
|
|
|
|
|
|
| 160 |
|
| 161 |
# Placement Stage (Deposit funds)
|
| 162 |
with gr.Column():
|
| 163 |
-
gr.Markdown("###
|
| 164 |
deposit_amount = gr.Textbox(placeholder="Enter deposit amount", label="Deposit Amount ($)")
|
| 165 |
-
|
|
|
|
| 166 |
deposit_btn = gr.Button("Deposit Funds")
|
| 167 |
|
| 168 |
-
#
|
| 169 |
with gr.Column():
|
| 170 |
-
gr.Markdown("###
|
| 171 |
-
transfer_amount = gr.Textbox(placeholder="Enter transfer amount", label="Transfer Amount ($)")
|
| 172 |
-
num_layers = gr.Slider(minimum=1, maximum=10, value=3, step=1, label="Number of Layers (Accounts)")
|
| 173 |
-
layer_btn = gr.Button("Transfer for Layering")
|
| 174 |
-
|
| 175 |
-
# Integration Stage (Withdraw to Destination)
|
| 176 |
-
with gr.Column():
|
| 177 |
-
gr.Markdown("### Integration: Withdraw to Destination")
|
| 178 |
withdraw_amount = gr.Textbox(placeholder="Enter withdrawal amount", label="Withdrawal Amount ($)")
|
| 179 |
-
card_type = gr.Dropdown(choices=["Credit Card", "Debit Card", "Prepaid Card"], label="
|
| 180 |
card_number = gr.Textbox(placeholder="Enter card number", label="Card Number")
|
| 181 |
expiry = gr.Textbox(placeholder="MM/YY", label="Expiry Date")
|
| 182 |
cvv = gr.Textbox(placeholder="CVV", label="CVV", type="password")
|
| 183 |
-
|
|
|
|
| 184 |
|
| 185 |
# Event handlers
|
| 186 |
-
login_btn.click(
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
outputs=[status_output, balance_output]
|
| 190 |
-
)
|
| 191 |
-
deposit_btn.click(
|
| 192 |
-
fn=process_deposit,
|
| 193 |
-
inputs=[email_input, password_input, deposit_amount, source_label],
|
| 194 |
-
outputs=[status_output, balance_output]
|
| 195 |
-
)
|
| 196 |
-
layer_btn.click(
|
| 197 |
-
fn=process_layering,
|
| 198 |
-
inputs=[email_input, password_input, transfer_amount, num_layers],
|
| 199 |
-
outputs=[status_output, balance_output]
|
| 200 |
-
)
|
| 201 |
-
withdraw_btn.click(
|
| 202 |
-
fn=process_withdrawal,
|
| 203 |
-
inputs=[email_input, password_input, withdraw_amount, card_type, card_number, expiry, cvv],
|
| 204 |
-
outputs=[status_output, balance_output]
|
| 205 |
-
)
|
| 206 |
-
|
| 207 |
-
# Dummy buttons for appearance
|
| 208 |
-
with gr.Row(elem_classes="buttons"):
|
| 209 |
-
gr.Button("Send")
|
| 210 |
-
gr.Button("Request")
|
| 211 |
-
gr.Button("Cash Card")
|
| 212 |
-
gr.Button("Bitcoin")
|
| 213 |
|
| 214 |
# Launch the app
|
| 215 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Dummy storage for balance display (real balance managed on backend)
|
| 5 |
mock_balance = 0.0
|
|
|
|
| 7 |
# Backend server URL (replace with your private server for real transactions)
|
| 8 |
BACKEND_URL = "http://your-private-server:5000" # Update with actual server address
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Function to connect to backend for balance update or retrieval
|
| 11 |
+
def fetch_balance():
|
| 12 |
global mock_balance
|
| 13 |
try:
|
| 14 |
+
response = requests.get(f"{BACKEND_URL}/balance")
|
| 15 |
if response.status_code == 200:
|
| 16 |
data = response.json()
|
| 17 |
mock_balance = data.get("balance", 0.0)
|
|
|
|
| 22 |
return f"Backend connection failed: {str(e)} (Using mock balance)", mock_balance
|
| 23 |
|
| 24 |
# Function for placement stage (deposit real funds)
|
| 25 |
+
def process_deposit(deposit_amount, payment_method, payment_details):
|
| 26 |
global mock_balance
|
| 27 |
try:
|
| 28 |
amount = float(deposit_amount)
|
| 29 |
if amount <= 0:
|
| 30 |
return "Deposit amount must be positive.", mock_balance
|
| 31 |
response = requests.post(f"{BACKEND_URL}/deposit", json={
|
| 32 |
+
"amount": amount, "method": payment_method, "details": payment_details
|
| 33 |
})
|
| 34 |
if response.status_code == 200:
|
| 35 |
data = response.json()
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
return f"Error: {str(e)} (Backend not reachable)", mock_balance
|
| 44 |
|
| 45 |
+
# Function for integration stage (withdraw to card)
|
| 46 |
+
def process_withdrawal(withdraw_amount, card_type, card_number, expiry, cvv, cardholder_name):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
global mock_balance
|
| 48 |
try:
|
| 49 |
amount = float(withdraw_amount)
|
| 50 |
if amount <= 0:
|
| 51 |
return "Invalid withdrawal amount.", mock_balance
|
| 52 |
response = requests.post(f"{BACKEND_URL}/withdraw", json={
|
| 53 |
+
"amount": amount, "card_type": card_type, "card_number": card_number,
|
| 54 |
+
"expiry": expiry, "cvv": cvv, "cardholder_name": cardholder_name
|
| 55 |
})
|
| 56 |
if response.status_code == 200:
|
| 57 |
data = response.json()
|
|
|
|
| 86 |
font-size: 28px;
|
| 87 |
margin: 20px 0;
|
| 88 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
button {
|
| 90 |
background-color: #ff66b2 !important;
|
| 91 |
color: white !important;
|
|
|
|
| 92 |
padding: 10px 20px !important;
|
| 93 |
font-size: 16px !important;
|
| 94 |
border-radius: 5px !important;
|
|
|
|
| 95 |
}
|
| 96 |
button:hover {
|
| 97 |
background-color: #ff3399 !important;
|
|
|
|
| 107 |
}
|
| 108 |
"""
|
| 109 |
|
| 110 |
+
# Define the Card Transfer interface
|
| 111 |
with gr.Blocks(css=custom_css) as demo:
|
| 112 |
+
gr.Markdown("<div class='header'>Pink Card Transfer System</div>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
# Balance display
|
| 115 |
with gr.Column(elem_classes="balance-box"):
|
| 116 |
balance_output = gr.Textbox(value="$0.00", label="Current Balance", interactive=False)
|
| 117 |
+
login_btn = gr.Button("Refresh Balance")
|
| 118 |
+
status_output = gr.Textbox(value="Not connected", label="Transaction Log", interactive=False, lines=10)
|
| 119 |
|
| 120 |
# Placement Stage (Deposit funds)
|
| 121 |
with gr.Column():
|
| 122 |
+
gr.Markdown("### Deposit Funds (Placement)")
|
| 123 |
deposit_amount = gr.Textbox(placeholder="Enter deposit amount", label="Deposit Amount ($)")
|
| 124 |
+
payment_method = gr.Dropdown(choices=["Prepaid Card", "Credit Card", "Bank Transfer", "Crypto"], label="Payment Method")
|
| 125 |
+
payment_details = gr.Textbox(placeholder="Enter payment source ID or token", label="Payment Details/Token")
|
| 126 |
deposit_btn = gr.Button("Deposit Funds")
|
| 127 |
|
| 128 |
+
# Integration Stage (Withdraw to Card)
|
| 129 |
with gr.Column():
|
| 130 |
+
gr.Markdown("### Withdraw to Card (Integration)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
withdraw_amount = gr.Textbox(placeholder="Enter withdrawal amount", label="Withdrawal Amount ($)")
|
| 132 |
+
card_type = gr.Dropdown(choices=["Credit Card", "Debit Card", "Prepaid Card"], label="Card Type")
|
| 133 |
card_number = gr.Textbox(placeholder="Enter card number", label="Card Number")
|
| 134 |
expiry = gr.Textbox(placeholder="MM/YY", label="Expiry Date")
|
| 135 |
cvv = gr.Textbox(placeholder="CVV", label="CVV", type="password")
|
| 136 |
+
cardholder_name = gr.Textbox(placeholder="Cardholder Name", label="Cardholder Name")
|
| 137 |
+
withdraw_btn = gr.Button("Withdraw to Card")
|
| 138 |
|
| 139 |
# Event handlers
|
| 140 |
+
login_btn.click(fn=fetch_balance, inputs=[], outputs=[status_output, balance_output])
|
| 141 |
+
deposit_btn.click(fn=process_deposit, inputs=[deposit_amount, payment_method, payment_details], outputs=[status_output, balance_output])
|
| 142 |
+
withdraw_btn.click(fn=process_withdrawal, inputs=[withdraw_amount, card_type, card_number, expiry, cvv, cardholder_name], outputs=[status_output, balance_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
# Launch the app
|
| 145 |
demo.launch()
|