kivilaid commited on
Commit
68474f5
·
1 Parent(s): 2fc62a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -9
app.py CHANGED
@@ -1,16 +1,43 @@
1
  import gradio as gr
 
 
2
 
 
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!"
 
 
 
 
 
6
 
 
7
 
8
- with gr.Blocks() as demo:
9
- name = gr.Textbox(label="Name")
10
- output = gr.Textbox(label="Output Box")
11
- greet_btn = gr.Button("Greet")
12
- greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
13
- gr.File()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  if __name__ == "__main__":
16
- demo.launch()
 
1
  import gradio as gr
2
+ import requests
3
+ import json
4
 
5
+ # Function for the Hello World interface
6
+ hello_world = gr.Interface(lambda name: "Hello " + name, "text", "text")
7
 
8
+ # Function for the Should we translate? interface
9
+ def check_input(input_string):
10
+ if not input_string.strip():
11
+ return "No words in the input."
12
+ words = input_string.split()
13
+ 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]
14
+ return " ".join(response)
15
 
16
+ should_we_translate = gr.Interface(check_input, "text", "text")
17
 
18
+ # Function for the Statistics interface
19
+ def statistics():
20
+ url = "https://api.locize.app/4a48f53b-4f59-4179-ade9-25766306c8ed/latest/en/translation"
21
+ try:
22
+ data = fetch_json(url)
23
+ stats = [
24
+ f"1. Total number of keys: {total_keys(data)}",
25
+ f"2. Total number of keys where value is the same: {keys_value_same(data)}",
26
+ f"3. Total number of keys where value is not the same as key: {keys_value_not_same(data)}",
27
+ f"4. Total number keys that do not contain any word or words: {keys_without_words(data)}",
28
+ f"5. Total number of keys that contain only a number: {keys_only_numbers(data)}",
29
+ f"6. Total number of keys that contain only a character: {keys_only_characters(data)}",
30
+ f"7. Total number of keys that contain only a single word: {keys_single_word(data)}",
31
+ f"8. Total number of keys that contain only words: {keys_only_words(data)}"
32
+ ]
33
+ return "\n".join(stats)
34
+ except Exception as e:
35
+ return str(e)
36
+
37
+ statistics_interface = gr.Interface(statistics, inputs=None, outputs="text")
38
+
39
+ # Creating a Tabbed Interface with the updated names
40
+ demo = gr.TabbedInterface([hello_world, should_we_translate, statistics_interface], ["Hello World", "Should we translate?", "Statistics"])
41
 
42
  if __name__ == "__main__":
43
+ demo.launch()