Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import string
|
4 |
+
import datetime
|
5 |
+
|
6 |
+
# Daftar produk dan kategori
|
7 |
+
categories = {
|
8 |
+
"Kategori A": ["Produk A1", "Produk A2", "Produk A3", "Produk A4", "Produk A5", "Produk A6"],
|
9 |
+
"Kategori B": ["Produk B1", "Produk B2", "Produk B3", "Produk B4", "Produk B5", "Produk B6"],
|
10 |
+
"Kategori C": ["Produk C1", "Produk C2", "Produk C3", "Produk C4", "Produk C5", "Produk C6"],
|
11 |
+
"Kategori D": ["Produk D1", "Produk D2", "Produk D3", "Produk D4", "Produk D5", "Produk D6"]
|
12 |
+
}
|
13 |
+
|
14 |
+
# Fungsi untuk membuat dokumen LaTeX
|
15 |
+
def create_latex(data, filename):
|
16 |
+
latex_content = r"""
|
17 |
+
\documentclass[a4paper,12pt]{article}
|
18 |
+
\usepackage[utf8]{inputenc}
|
19 |
+
\usepackage[T1]{fontenc}
|
20 |
+
\usepackage{lmodern}
|
21 |
+
\usepackage{geometry}
|
22 |
+
\geometry{margin=1in}
|
23 |
+
\usepackage{booktabs}
|
24 |
+
\usepackage{fancyhdr}
|
25 |
+
\pagestyle{fancy}
|
26 |
+
\fancyhf{}
|
27 |
+
\fancyhead[C]{Dokumen Penawaran \\ PT. Contoh Perusahaan \\ Jl. Contoh Alamat No. 123}
|
28 |
+
\fancyfoot[C]{\thepage}
|
29 |
+
|
30 |
+
\begin{document}
|
31 |
+
|
32 |
+
\begin{center}
|
33 |
+
\textbf{\LARGE Dokumen Penawaran} \\
|
34 |
+
\vspace{0.5cm}
|
35 |
+
PT. Contoh Perusahaan \\
|
36 |
+
Jl. Contoh Alamat No. 123 \\
|
37 |
+
\vspace{0.5cm}
|
38 |
+
\end{center}
|
39 |
+
|
40 |
+
Kepada Yth. \\
|
41 |
+
\textbf{""" + data['nama_prospek'] + r"""} \\
|
42 |
+
""" + data['alamat_prospek'] + r""" \\
|
43 |
+
Jenis Prospek: """ + data['jenis_prospek'] + r""" \\
|
44 |
+
\vspace{0.5cm}
|
45 |
+
|
46 |
+
Tanggal: """ + data['tanggal'] + r""" \\
|
47 |
+
\vspace{0.5cm}
|
48 |
+
|
49 |
+
\textbf{Daftar Produk yang Ditawarkan:} \\
|
50 |
+
\begin{tabular}{|l|c|r|}
|
51 |
+
\hline
|
52 |
+
\textbf{Nama Produk} & \textbf{Jumlah} & \textbf{Harga (Rp)} \\
|
53 |
+
\hline
|
54 |
+
""" + "\n ".join([f"{p['nama']} & {p['jumlah']} & {p['harga']:,}" for p in data['produk']]) + r""" \\
|
55 |
+
\hline
|
56 |
+
\end{tabular}
|
57 |
+
\vspace{0.5cm}
|
58 |
+
|
59 |
+
Diskon: """ + (f"{data['diskon']}\%" if 'diskon' in data else "Tidak ada") + r""" \\
|
60 |
+
\vspace{0.5cm}
|
61 |
+
|
62 |
+
""" + (r"""\textbf{Syarat dan Ketentuan:} \\
|
63 |
+
""" + data['syarat'] + r""" \\
|
64 |
+
\vspace{0.5cm}""" if 'syarat' in data else r"Syarat dan Ketentuan: Tidak ada \\ \vspace{0.5cm}") + r"""
|
65 |
+
|
66 |
+
Hormat kami, \\
|
67 |
+
\vspace{0.5cm}
|
68 |
+
PT. Contoh Perusahaan
|
69 |
+
|
70 |
+
\end{document}
|
71 |
+
"""
|
72 |
+
with open(filename, "w") as f:
|
73 |
+
f.write(latex_content)
|
74 |
+
return filename
|
75 |
+
|
76 |
+
# Fungsi untuk memproses input dan membuat penawaran
|
77 |
+
def buat_penawaran(nama_prospek, alamat_prospek, jenis_prospek, produk_dipilih, jumlah_produk, harga_produk, diskon, tanggal, syarat):
|
78 |
+
data = {
|
79 |
+
'nama_prospek': nama_prospek if nama_prospek else "Prospek Tanpa Nama",
|
80 |
+
'alamat_prospek': alamat_prospek if alamat_prospek else "Alamat Tidak Diketahui",
|
81 |
+
'jenis_prospek': jenis_prospek if jenis_prospek else "Individu",
|
82 |
+
'tanggal': tanggal if tanggal else datetime.date.today().strftime("%Y-%m-%d"),
|
83 |
+
'produk': []
|
84 |
+
}
|
85 |
+
|
86 |
+
# Proses produk
|
87 |
+
if produk_dipilih and jumlah_produk and harga_produk:
|
88 |
+
try:
|
89 |
+
jumlah_list = [int(x.strip()) for x in jumlah_produk.split(",") if x.strip()]
|
90 |
+
harga_list = [int(x.strip()) for x in harga_produk.split(",") if x.strip()]
|
91 |
+
for i, p in enumerate(produk_dipilih):
|
92 |
+
j = jumlah_list[i] if i < len(jumlah_list) else 1
|
93 |
+
h = harga_list[i] if i < len(harga_list) else 100000
|
94 |
+
data['produk'].append({'nama': p, 'jumlah': j, 'harga': h})
|
95 |
+
except ValueError:
|
96 |
+
data['produk'].append({'nama': "Produk Contoh", 'jumlah': 1, 'harga': 100000})
|
97 |
+
warning = "Peringatan: Format jumlah atau harga produk salah. Diganti dengan data contoh."
|
98 |
+
else:
|
99 |
+
data['produk'].append({'nama': "Produk Contoh", 'jumlah': 1, 'harga': 100000})
|
100 |
+
|
101 |
+
if diskon:
|
102 |
+
data['diskon'] = diskon
|
103 |
+
if syarat:
|
104 |
+
data['syarat'] = syarat
|
105 |
+
|
106 |
+
# Validasi data
|
107 |
+
missing_data = []
|
108 |
+
if not nama_prospek:
|
109 |
+
missing_data.append("Nama Prospek")
|
110 |
+
if not alamat_prospek:
|
111 |
+
missing_data.append("Alamat Prospek")
|
112 |
+
if not jenis_prospek:
|
113 |
+
missing_data.append("Jenis Prospek")
|
114 |
+
if not tanggal:
|
115 |
+
missing_data.append("Tanggal")
|
116 |
+
if not produk_dipilih or not jumlah_produk or not harga_produk:
|
117 |
+
missing_data.append("Produk, Jumlah, atau Harga")
|
118 |
+
|
119 |
+
warning = ""
|
120 |
+
if missing_data:
|
121 |
+
warning = "Peringatan: Data berikut kurang dan telah diisi dengan asumsi: " + ", ".join(missing_data) + ". Silakan lengkapi data jika perlu."
|
122 |
+
|
123 |
+
# Buat file LaTeX
|
124 |
+
filename = ''.join(random.choices(string.ascii_letters + string.digits, k=10)) + ".tex"
|
125 |
+
latex_file = create_latex(data, filename)
|
126 |
+
return latex_file, warning
|
127 |
+
|
128 |
+
# Interface Gradio
|
129 |
+
with gr.Blocks() as demo:
|
130 |
+
gr.Markdown("# Aplikasi Pembuatan Dokumen Penawaran")
|
131 |
+
|
132 |
+
with gr.Row():
|
133 |
+
nama_prospek = gr.Textbox(label="Nama Prospek")
|
134 |
+
alamat_prospek = gr.Textbox(label="Alamat Prospek")
|
135 |
+
jenis_prospek = gr.Dropdown(choices=["Individu", "Perusahaan", "Kafe"], label="Jenis Prospek")
|
136 |
+
|
137 |
+
with gr.Row():
|
138 |
+
tanggal = gr.Textbox(label="Tanggal Penawaran (YYYY-MM-DD)")
|
139 |
+
|
140 |
+
with gr.Row():
|
141 |
+
produk_dipilih = gr.CheckboxGroup(choices=[p for cat in categories.values() for p in cat], label="Pilih Produk")
|
142 |
+
jumlah_produk = gr.Textbox(label="Jumlah Produk (pisahkan dengan koma)")
|
143 |
+
harga_produk = gr.Textbox(label="Harga per Produk (Rp, pisahkan dengan koma)")
|
144 |
+
|
145 |
+
with gr.Row():
|
146 |
+
diskon = gr.Textbox(label="Diskon (%)")
|
147 |
+
syarat = gr.Textbox(label="Syarat dan Ketentuan")
|
148 |
+
|
149 |
+
submit_button = gr.Button("Buat Penawaran")
|
150 |
+
|
151 |
+
output_file = gr.File(label="Download Dokumen Penawaran (LaTeX, akan dirender sebagai PDF)")
|
152 |
+
warning_text = gr.Textbox(label="Peringatan")
|
153 |
+
|
154 |
+
submit_button.click(
|
155 |
+
buat_penawaran,
|
156 |
+
inputs=[nama_prospek, alamat_prospek, jenis_prospek, produk_dipilih, jumlah_produk, harga_produk, diskon, tanggal, syarat],
|
157 |
+
outputs=[output_file, warning_text]
|
158 |
+
)
|
159 |
+
|
160 |
+
demo.launch()
|