yaml-parser / app.py
Teddy Xinyuan Chen
Initial commit
841271b unverified
raw
history blame contribute delete
741 Bytes
import gradio as gr
import yaml
from pprint import pformat
def parse_yaml(yaml_input):
try:
parsed_yaml = yaml.safe_load(yaml_input)
return pformat(parsed_yaml)
except yaml.YAMLError as e:
return f"Error: {e}"
# with gr.Blocks() as demo:
# Define the Gradio interface
demo = gr.Interface(
fn=parse_yaml,
inputs=gr.inputs.Textbox(lines=10, placeholder="Enter YAML here..."),
outputs=gr.outputs.Textbox(),
title="YAML Parser",
description="Enter YAML input and get the parsed result",
examples=[
'''\
name: John Doe
age: 30
city: New York
hobbies:
- hiking
- photography
- programming
''',
],
)
# Launch the Gradio app
if __name__ == "__main__":
demo.launch()