Aditya DN commited on
Commit
faa2ea4
·
verified ·
1 Parent(s): b434367

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -2,18 +2,29 @@ import gradio as gr
2
  import base64
3
 
4
  def buffer_to_base64(binary_data: bytes):
5
- # Langsung encode bytes ke Base64 string
6
  b64_str = base64.b64encode(binary_data).decode("utf-8")
7
  return b64_str
8
 
9
  with gr.Blocks() as demo:
10
  gr.Markdown("# ESP32 Buffer to Base64 API")
11
  with gr.Row():
12
- # type="binary" akan mengirimkan bytes langsung
13
  inp = gr.File(label="Upload Raw Buffer", type="binary")
14
- out = gr.Textbox(label="Base64 Output")
15
- btn = gr.Button("Convert")
16
- btn.click(buffer_to_base64, inputs=inp, outputs=out)
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  if __name__ == "__main__":
19
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
2
  import base64
3
 
4
  def buffer_to_base64(binary_data: bytes):
5
+ # Encode bytes ke Base64 string
6
  b64_str = base64.b64encode(binary_data).decode("utf-8")
7
  return b64_str
8
 
9
  with gr.Blocks() as demo:
10
  gr.Markdown("# ESP32 Buffer to Base64 API")
11
  with gr.Row():
 
12
  inp = gr.File(label="Upload Raw Buffer", type="binary")
13
+ out = gr.Textbox(label="Base64 Output", lines=6)
14
+ with gr.Row():
15
+ btn_convert = gr.Button("Convert")
16
+ btn_copy = gr.Button("Copy to Clipboard")
17
+
18
+ # Tombol Convert
19
+ btn_convert.click(buffer_to_base64, inputs=inp, outputs=out)
20
+
21
+ # Tombol Copy pakai JS bawaan browser
22
+ btn_copy.click(
23
+ None,
24
+ [],
25
+ [],
26
+ js="navigator.clipboard.writeText(document.querySelector('textarea').value)"
27
+ )
28
 
29
  if __name__ == "__main__":
30
  demo.launch(server_name="0.0.0.0", server_port=7860)