Bayhaqy commited on
Commit
32647ef
·
verified ·
1 Parent(s): fcf4421

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Data dummy awal (list of dicts)
4
+ data = []
5
+
6
+ def create_entry(username, countrycode, sbucode, brandcode, conceptcode, channel):
7
+ new_entry = {
8
+ "USERNAME": username,
9
+ "COUNTRYCODE": countrycode,
10
+ "SBUCODE": sbucode,
11
+ "BRANDCODE": brandcode,
12
+ "CONCEPTCODE": conceptcode,
13
+ "CHANNEL": channel
14
+ }
15
+ data.append(new_entry)
16
+ return "Entry added!", show_data()
17
+
18
+ def show_data():
19
+ return "\n".join([f"{i+1}. {entry}" for i, entry in enumerate(data)]) or "No data yet."
20
+
21
+ def delete_entry(index):
22
+ try:
23
+ index = int(index) - 1
24
+ if 0 <= index < len(data):
25
+ deleted = data.pop(index)
26
+ return f"Deleted: {deleted}", show_data()
27
+ else:
28
+ return "Invalid index", show_data()
29
+ except:
30
+ return "Enter a valid number", show_data()
31
+
32
+ with gr.Blocks() as demo:
33
+ gr.Markdown("## Simple CRUD App")
34
+
35
+ with gr.Row():
36
+ username = gr.Textbox(label="USERNAME")
37
+ country = gr.Textbox(label="COUNTRYCODE")
38
+ sbu = gr.Textbox(label="SBUCODE")
39
+ brand = gr.Textbox(label="BRANDCODE")
40
+ concept = gr.Textbox(label="CONCEPTCODE")
41
+ channel = gr.Textbox(label="CHANNEL")
42
+
43
+ create_btn = gr.Button("Add Entry")
44
+ output_text = gr.Textbox(label="Current Data", lines=10)
45
+
46
+ create_btn.click(
47
+ create_entry,
48
+ inputs=[username, country, sbu, brand, concept, channel],
49
+ outputs=[gr.Textbox(visible=False), output_text]
50
+ )
51
+
52
+ with gr.Row():
53
+ del_index = gr.Textbox(label="Delete Entry No")
54
+ delete_btn = gr.Button("Delete")
55
+
56
+ delete_btn.click(delete_entry, inputs=del_index, outputs=[gr.Textbox(visible=False), output_text])
57
+
58
+ gr.Markdown("### Current Records:")
59
+ show_btn = gr.Button("Refresh Data")
60
+ show_btn.click(fn=lambda: "", outputs=gr.Textbox(visible=False)) # Dummy refresh trigger
61
+ show_btn.click(fn=show_data, outputs=output_text)
62
+
63
+ demo.launch()