Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Function to convert JSON to formatted text
|
| 6 |
+
def json_to_text(filename):
|
| 7 |
+
with open(filename, 'r') as json_file:
|
| 8 |
+
data = json.load(json_file)
|
| 9 |
+
|
| 10 |
+
text = f"### {filename}\n\n"
|
| 11 |
+
text += json.dumps(data, indent=2)
|
| 12 |
+
return text
|
| 13 |
+
|
| 14 |
+
# List available JSON files
|
| 15 |
+
def list_json_files():
|
| 16 |
+
return [f for f in os.listdir('.') if f.endswith('.json')]
|
| 17 |
+
|
| 18 |
+
# Gradio Interface
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=json_to_text,
|
| 21 |
+
inputs=gr.Dropdown(choices=json_to_text_files := json_to_text_files if (json_to_text_files := json_to_text_files) else json_to_text_files, label="Select JSON File"),
|
| 22 |
+
outputs=gr.Markdown(),
|
| 23 |
+
title="JSON to Text Converter",
|
| 24 |
+
description="Select a JSON file from the dropdown to view its content as formatted text."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
json_to_text_files = json_to_text_files if (json_to_text_files := list(json_to_text_files if (json_to_text_files := list(filter(lambda x: x.endswith('.json'), os.listdir('.')))) else json_to_text_files)) else json_to_text_files
|
| 29 |
+
iface.inputs.choices = json_to_text_files
|
| 30 |
+
iface.launch()
|