File size: 741 Bytes
841271b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
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()