jsonText / app.py
nikrizal's picture
Update app.py
3ee08f9
raw
history blame
741 Bytes
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()