Admin-002 commited on
Commit
c0a0088
1 Parent(s): 881e425

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -0
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import os
3
+ import shutil
4
+ import zipfile
5
+ import tempfile
6
+ import matplotlib.pyplot as plt
7
+ from matplotlib.patches import FancyBboxPatch, Circle, Rectangle
8
+ import gradio as gr
9
+
10
+ def plot_mobile_bank_slip_from_excel(excel_file):
11
+ # Load data from the Excel file
12
+ df = pd.read_excel(excel_file)
13
+
14
+ # Create a temporary directory to store images
15
+ temp_dir = tempfile.mkdtemp()
16
+
17
+ # Iterate over each record and generate the image
18
+ for index, row in df.iterrows():
19
+ status = row['Status']
20
+ reference_no = row['reference_no']
21
+ total_amount = row['total_amount']
22
+ payee_name = row['payee_name']
23
+ to_account_no = row['to_account_no']
24
+
25
+ # Create a figure and axis
26
+ fig, ax = plt.subplots(figsize=(6, 10))
27
+
28
+ # Draw sections with curved corners
29
+ successful_patch = FancyBboxPatch((0, 0.85), 1, 0.1, boxstyle="round,pad=0.1", ec="none", fc='green' if status == "Successful" else 'yellow' if status == "Pending" else 'Red', alpha=0.5)
30
+ transaction_patch = FancyBboxPatch((0, 0.4), 1, 0.1, boxstyle="round,pad=0.1", ec="none", fc='lightblue', alpha=0.5)
31
+ ax.add_patch(successful_patch)
32
+ ax.add_patch(transaction_patch)
33
+
34
+ # Draw title
35
+ ax.text(0.5, 0.9, "Transaction Status", color='navy', fontsize=24, ha='center')
36
+
37
+ # Draw payment status
38
+ ax.text(0.5, 0.85, f" {status}", color='black', fontsize=16, ha='center')
39
+
40
+ # Draw transaction ID
41
+ ax.text(0.5, 0.8, f"Reference no: {reference_no}", color='black', fontsize=12, ha='center')
42
+
43
+ # Draw total amount
44
+ ax.text(0.5, 0.71, "Total Amount Transferred", color='black', fontsize=12, ha='center')
45
+ ax.text(0.5, 0.67, f"₹{total_amount}", color='black', fontsize=20, ha='center')
46
+
47
+ # Extract first letter from first name and last name
48
+ first_name, last_name = payee_name.split() if payee_name else ("?", "?")
49
+ first_initial, last_initial = first_name[0].upper(), last_name[0].upper()
50
+
51
+ # Draw circular profile with initials
52
+ profile_circle = Circle((0.5, 0.6), 0.04, color='#05cdf5')
53
+ ax.add_patch(profile_circle)
54
+ ax.text(0.5, 0.6, f"{first_initial}{last_initial}", color='black', fontsize=12, ha='center', va='center')
55
+
56
+ # Draw payee details and values
57
+ details = {"Payee": payee_name, "To Account No": to_account_no}
58
+ max_len = max(len(detail) for detail in details.keys())
59
+ for i, (detail, value) in enumerate(details.items()):
60
+ ax.text(0.1, 0.45 - i * 0.06, f"{detail.ljust(max_len)}", color='black', fontsize=14, ha='left')
61
+ ax.text(0.9, 0.45 - i * 0.06, f"{value}", color='black', fontsize=14, ha='right')
62
+
63
+ # Draw buttons with symbols
64
+ button_width = 0.50
65
+ button_height = 0.05
66
+ button_x_share = 0.2 - button_width / 2
67
+ button_x_download = 0.75 - button_width / 2
68
+ ax.add_patch(Rectangle((button_x_share, 0.15 - button_height / 2), button_width, button_height, edgecolor='none', facecolor='#f4a460'))
69
+ ax.add_patch(Rectangle((button_x_download, 0.15 - button_height / 2), button_width, button_height, edgecolor='none', facecolor='#34c3eb'))
70
+ ax.text(0.225, 0.15, "Share Receipt", color='white', fontsize=14, ha='center', va='center')
71
+ ax.text(0.75, 0.15, "Download Receipt", color='white', fontsize=14, ha='center', va='center')
72
+
73
+ # Set axis limits and remove ticks
74
+ ax.set_xlim(0, 1)
75
+ ax.set_ylim(0, 1)
76
+ ax.axis('off')
77
+
78
+ # Save the image
79
+ image_filename = f"{temp_dir}/transaction_{index + 1}.png"
80
+ plt.savefig(image_filename, bbox_inches='tight', pad_inches=0.1)
81
+ plt.close()
82
+
83
+ # Create a zip file containing the images
84
+ shutil.make_archive(temp_dir, 'zip', temp_dir)
85
+ zip_file_path = f"{temp_dir}.zip"
86
+
87
+ return zip_file_path
88
+
89
+ # Create the Gradio interface
90
+ inputs = gr.File(label="Upload Excel File")
91
+ outputs = gr.File(label="Download Output Images")
92
+ gr.Interface(fn=plot_mobile_bank_slip_from_excel, inputs=inputs, outputs=outputs).launch()