File size: 741 Bytes
3ee08f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
import json

# Define a function that takes a JSON object as input
def process_json(input_json):
    # Parse the JSON object
    data = json.loads(input_json)
    
    # Your logic here to process the data
    # For example, let's say we want to extract a "name" field from the JSON
    name = data.get("name", "Unknown")

    # Create a response JSON object
    response_json = {"message": f"Hello, {name}!"}

    # Convert the response JSON object to a string
    response_str = json.dumps(response_json)
    
    return response_str

# Create a Gradio interface for the function that accepts JSON input
iface = gr.Interface(fn=process_json, inputs='json', outputs='json')

# Launch the Gradio interface
iface.launch()