kivilaid commited on
Commit
7742e91
·
1 Parent(s): f63ea63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -31
app.py CHANGED
@@ -1,37 +1,15 @@
1
  import gradio as gr
2
- import json
3
 
4
- def minify_json(input_json=None, input_file=None):
5
- try:
6
- # Determine input type (text or file)
7
- if input_json:
8
- data = json.loads(input_json)
9
- elif input_file:
10
- data = json.load(input_file.file)
11
- else:
12
- return "No input provided.", None
13
 
14
- # Minify the JSON
15
- minified_json = json.dumps(data, separators=(',', ':'))
16
- return minified_json, minified_json
17
- except json.JSONDecodeError as e:
18
- return f"Invalid JSON format: {str(e)}", None
19
 
20
- # Define the Gradio interface
21
- iface = gr.Interface(
22
- fn=minify_json,
23
- inputs=[
24
- gr.Textbox(label="Input JSON (Text)", placeholder="Enter JSON here...", lines=10),
25
- gr.File(label="Input JSON (File)", type="filepath")
26
- ],
27
- outputs=[
28
- gr.Textbox(label="Minified JSON (Text)", lines=10),
29
- gr.File(label="Minified JSON (Download)", type="json")
30
- ],
31
- title="JSON Minifier",
32
- description="Upload a JSON file or paste JSON text to minify it."
33
- )
34
 
35
- # Launch the app
 
 
 
 
 
36
  if __name__ == "__main__":
37
- iface.launch()
 
1
  import gradio as gr
 
2
 
 
 
 
 
 
 
 
 
 
3
 
4
+ def greet(name):
5
+ return "Hello " + name + "!"
 
 
 
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ with gr.Blocks() as demo:
9
+ name = gr.Textbox(label="Name")
10
+ output = gr.Textbox(label="Output Box")
11
+ greet_btn = gr.Button("Greet")
12
+ greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
13
+
14
  if __name__ == "__main__":
15
+ demo.launch()