jsonText / app.py
nikrizal's picture
uuid
45f7450
raw
history blame contribute delete
875 Bytes
import gradio as gr
import json
import uuid
# Define a function that takes a JSON object as input
def process_json(input_json):
id = uuid.uuid1()
# 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
user_id = data.get("user_id", "Unknown")
user_token = data.get("user_token", "Unknown")
# Create a response JSON object
response_json = {"message": f"Hello, {user_id}!{user_token} random uuid {id.int}"}
# 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='text', outputs='json')
# Launch the Gradio interface
iface.launch()