nikrizal commited on
Commit
3ee08f9
·
1 Parent(s): 4377b1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+
4
+ # Define a function that takes a JSON object as input
5
+ def process_json(input_json):
6
+ # Parse the JSON object
7
+ data = json.loads(input_json)
8
+
9
+ # Your logic here to process the data
10
+ # For example, let's say we want to extract a "name" field from the JSON
11
+ name = data.get("name", "Unknown")
12
+
13
+ # Create a response JSON object
14
+ response_json = {"message": f"Hello, {name}!"}
15
+
16
+ # Convert the response JSON object to a string
17
+ response_str = json.dumps(response_json)
18
+
19
+ return response_str
20
+
21
+ # Create a Gradio interface for the function that accepts JSON input
22
+ iface = gr.Interface(fn=process_json, inputs='json', outputs='json')
23
+
24
+ # Launch the Gradio interface
25
+ iface.launch()