kivilaid commited on
Commit
171689f
·
1 Parent(s): 77b1244

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+
4
+ def minify_json(input_json):
5
+ try:
6
+ # Load JSON from string or file
7
+ if isinstance(input_json, str):
8
+ data = json.loads(input_json)
9
+ else: # file input
10
+ data = json.load(input_json)
11
+
12
+ # Minify the JSON
13
+ minified_json = json.dumps(data, separators=(',', ':'))
14
+
15
+ return minified_json, minified_json
16
+ except json.JSONDecodeError:
17
+ return "Invalid JSON format.", ""
18
+
19
+ # Define the Gradio interface
20
+ iface = gr.Interface(
21
+ fn=minify_json,
22
+ inputs=[
23
+ gr.Textbox(label="Input JSON (Text)", placeholder="Enter JSON here...", lines=10),
24
+ gr.File(label="Input JSON (File)", type="file", optional=True)
25
+ ],
26
+ outputs=[
27
+ gr.Textbox(label="Minified JSON (Text)", lines=10),
28
+ gr.File(label="Minified JSON (Download)", type="json")
29
+ ],
30
+ title="JSON Minifier",
31
+ description="Upload a JSON file or paste JSON text to minify it."
32
+ )
33
+
34
+ # Launch the app
35
+ iface.launch()