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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -25
app.py CHANGED
@@ -1,38 +1,33 @@
1
  import gradio as gr
 
2
 
3
  # Function for the Minify interface
4
- def minify_function(input_text, uploaded_file):
5
- if uploaded_file is not None:
6
- content = uploaded_file.read().decode("utf-8")
7
- else:
8
- content = input_text
9
- return "Hello " + content
10
 
11
- minify = gr.Interface(
12
- minify_function,
13
- [gr.Textbox(label="Input Text"), gr.File(label="Upload File")],
14
- "text"
15
- )
16
 
17
- # Function for the Should we translate? interface
18
- def check_input(input_text, uploaded_file):
19
- if uploaded_file is not None:
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
- should_we_translate = gr.Interface(
29
- check_input,
30
- [gr.Textbox(label="Input Text"), gr.File(label="Upload File")],
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()