kivilaid commited on
Commit
b7e8935
·
1 Parent(s): 98483eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -1,30 +1,42 @@
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?"])
 
1
  import gradio as gr
2
  import json
3
 
4
+ # Function to minify JSON
5
  def minify_json(input_text, uploaded_file):
6
  try:
 
7
  if uploaded_file is not None:
8
  input_text = uploaded_file.read().decode("utf-8")
 
 
 
9
 
10
+ # Load JSON content from input text or file
11
+ json_content = json.loads(input_text)
12
+ # Minify JSON (compact representation)
13
+ minified_json = json.dumps(json_content, separators=(',', ':'))
14
  return minified_json
15
  except json.JSONDecodeError:
16
+ return "Invalid JSON input. Please provide a valid JSON."
17
 
18
  minify = gr.Interface(
19
  minify_json,
20
+ [gr.Textbox(label="Input JSON Text"), gr.File(label="Upload JSON File")],
21
  "text"
22
  )
23
 
24
+ # Existing Should We Translate Interface
25
+ def check_input(input_text, uploaded_file):
26
+ if uploaded_file is not None:
27
+ input_text = uploaded_file.read().decode("utf-8")
28
+
29
+ if not input_text.strip():
30
+ return "No words in the input."
31
+ words = input_text.split()
32
+ 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]
33
+ return " ".join(response)
34
+
35
+ should_we_translate = gr.Interface(
36
+ check_input,
37
+ [gr.Textbox(label="Input Text"), gr.File(label="Upload File")],
38
+ "text"
39
+ )
40
 
41
  # Creating a Tabbed Interface with updated functionalities
42
  demo = gr.TabbedInterface([minify, should_we_translate], ["Minify JSON", "Should we translate?"])