Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,33 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
# Function for the Minify interface
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
return "Hello " + content
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
)
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
input_text = uploaded_file.read().decode("utf-8")
|
| 21 |
-
|
| 22 |
-
if not input_text.strip():
|
| 23 |
-
return "No words in the input."
|
| 24 |
-
words = input_text.split()
|
| 25 |
-
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]
|
| 26 |
-
return " ".join(response)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
[gr.Textbox(label="Input
|
| 31 |
"text"
|
| 32 |
)
|
| 33 |
|
|
|
|
|
|
|
| 34 |
# Creating a Tabbed Interface with updated functionalities
|
| 35 |
-
demo = gr.TabbedInterface([minify, should_we_translate], ["Minify", "Should we translate?"])
|
| 36 |
|
| 37 |
if __name__ == "__main__":
|
| 38 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
|
| 4 |
# Function for the Minify interface
|
| 5 |
+
def minify_json(input_text, uploaded_file):
|
| 6 |
+
try:
|
| 7 |
+
# Load JSON from file if provided
|
| 8 |
+
if uploaded_file is not None:
|
| 9 |
+
input_text = uploaded_file.read().decode("utf-8")
|
|
|
|
| 10 |
|
| 11 |
+
# Parse the JSON
|
| 12 |
+
json_data = json.loads(input_text)
|
| 13 |
+
|
| 14 |
+
# Minify the JSON
|
| 15 |
+
minified_json = json.dumps(json_data, separators=(',', ':'))
|
| 16 |
|
| 17 |
+
return minified_json
|
| 18 |
+
except json.JSONDecodeError:
|
| 19 |
+
return "Invalid JSON input."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
minify = gr.Interface(
|
| 22 |
+
minify_json,
|
| 23 |
+
[gr.Textbox(label="Input JSON"), gr.File(label="Upload JSON File")],
|
| 24 |
"text"
|
| 25 |
)
|
| 26 |
|
| 27 |
+
# (The 'Should we translate?' interface code remains the same)
|
| 28 |
+
|
| 29 |
# Creating a Tabbed Interface with updated functionalities
|
| 30 |
+
demo = gr.TabbedInterface([minify, should_we_translate], ["Minify JSON", "Should we translate?"])
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
demo.launch()
|