import gradio as gr import json # Function to minify JSON def minify_json(input_text, uploaded_file): try: if uploaded_file is not None: input_text = uploaded_file.read().decode("utf-8") # Load JSON content from input text or file json_content = json.loads(input_text) # Minify JSON (compact representation) minified_json = json.dumps(json_content, separators=(',', ':')) return minified_json except json.JSONDecodeError: return "Invalid JSON input. Please provide a valid JSON." minify = gr.Interface( minify_json, [gr.Textbox(label="Input JSON Text"), gr.File(label="Upload JSON File")], "text" ) # Existing Should We Translate Interface def check_input(input_text, uploaded_file): if uploaded_file is not None: input_text = uploaded_file.read().decode("utf-8") if not input_text.strip(): return "No words in the input." words = input_text.split() response = [f"'{word}' is a valid word." if word.isalpha() and ' ' not in word else f"'{word}' is not a valid word." for word in words] return " ".join(response) should_we_translate = gr.Interface( check_input, [gr.Textbox(label="Input Text"), gr.File(label="Upload File")], "text" ) # Creating a Tabbed Interface with updated functionalities demo = gr.TabbedInterface([minify, should_we_translate], ["Minify JSON", "Should we translate?"]) if __name__ == "__main__": demo.launch()