camilosegura commited on
Commit
6b85a0f
1 Parent(s): 173536d

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. README.md +2 -2
  2. __pycache__/app.cpython-310.pyc +0 -0
  3. app.py +41 -19
  4. src/demo/app.py +41 -19
  5. src/pyproject.toml +1 -1
README.md CHANGED
@@ -2,8 +2,8 @@
2
  ---
3
  tags: [gradio-custom-component, gradio-template-SimpleTextbox]
4
  title: gradio_keyboardtextboxcomponent V0.0.1
5
- colorFrom: purple
6
- colorTo: purple
7
  sdk: docker
8
  pinned: false
9
  license: apache-2.0
 
2
  ---
3
  tags: [gradio-custom-component, gradio-template-SimpleTextbox]
4
  title: gradio_keyboardtextboxcomponent V0.0.1
5
+ colorFrom: red
6
+ colorTo: gray
7
  sdk: docker
8
  pinned: false
9
  license: apache-2.0
__pycache__/app.cpython-310.pyc CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
 
app.py CHANGED
@@ -4,20 +4,11 @@ from gradio_keyboardtextboxcomponent import KeyboardTextBoxComponent
4
  import json
5
  import requests
6
 
7
- API_URL_LIST = "https://jsonplaceholder.typicode.com/todos"
 
8
 
9
  # Una aplicación con un listado de traducciones pendientes
10
  # presionar sobre una
11
- def translation_chat_fn(translation_index, modification):
12
- # transform index to id
13
- # submit to api
14
-
15
- response = requests.get(API_URL_LIST) # TODO: Post
16
- response.json()
17
- print(response.json())
18
-
19
- api_response = True
20
- return "Traducción corregida" if api_response else "Error del servicio"
21
 
22
  selected_translation_index = 0
23
 
@@ -25,12 +16,43 @@ selected_translation_index = 0
25
  # {"id": 0, "text_spa": "The quick brown fox jumps over the lazy dog", "text_gum": "El rápido zorro café salta sobre los perezosos perros"},
26
  # {"id": 1, "text_spa": "Build & share delightful machine learning apps", "text_gum": "Construye y comparte encantadoras aplicaciones de aprendizaje de máquina"},
27
  # ]
28
- translations_response = requests.get(API_URL_LIST).json() # TODO: Post
29
- translations = list(map(lambda x: [x["title"]], translations_response))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  # Interface Components
32
  with gr.Blocks() as demo:
33
- translations_dataset_input = gr.Dataset(components=[gr.Textbox(visible=False)],# gr.Textbox(visible=False)],
34
 
35
  label="Traducciones",
36
  samples=translations,
@@ -38,22 +60,22 @@ with gr.Blocks() as demo:
38
  samples_per_page=10
39
  )
40
  gum_keyboard_textbox_input = KeyboardTextBoxComponent(#value=translations[selected_translation_index][0],
41
- label="Traducciones",
42
  #info="Elige las traducciones que desees revisar"
43
  )
44
-
45
  # Interactions
46
  def assign_trasnlation_id(evt: gr.SelectData):
47
  # selected_translation_index = evt.index
48
- # print(evt)
49
- return translations[evt.index][0]
50
- translations_dataset_input.select(fn=assign_trasnlation_id, outputs=[gum_keyboard_textbox_input])
51
 
52
  # Interface
53
  gr.Interface(
54
  translation_chat_fn,
55
  [
56
  translations_dataset_input,
 
57
  gum_keyboard_textbox_input,
58
  ],
59
  "text",
 
4
  import json
5
  import requests
6
 
7
+ API_URL_LIST = "https://2xp1wr4k54.execute-api.us-east-1.amazonaws.com/dev/v1/translations/index"
8
+ API_URL_UPDATE = "https://2xp1wr4k54.execute-api.us-east-1.amazonaws.com/dev/v1/translations/update"
9
 
10
  # Una aplicación con un listado de traducciones pendientes
11
  # presionar sobre una
 
 
 
 
 
 
 
 
 
 
12
 
13
  selected_translation_index = 0
14
 
 
16
  # {"id": 0, "text_spa": "The quick brown fox jumps over the lazy dog", "text_gum": "El rápido zorro café salta sobre los perezosos perros"},
17
  # {"id": 1, "text_spa": "Build & share delightful machine learning apps", "text_gum": "Construye y comparte encantadoras aplicaciones de aprendizaje de máquina"},
18
  # ]
19
+ request = {
20
+ "data": {
21
+ "per_page": 10
22
+ }
23
+ }
24
+ translations_response = requests.post(API_URL_LIST, json=request)
25
+ #json.loads(str(response["Item"]).replace("'", '"').encode('utf-8'))
26
+ translations_response=json.loads(json.dumps(translations_response.json()).replace("'", '"').encode('utf-8'))["records"]
27
+ translations = list(map(lambda x: [f'{x["gum"]} : {x["es"]}', x["gum"], x["es"], x["translation_timestamp"]], translations_response))
28
+
29
+ # print(translations)
30
+
31
+ def translation_chat_fn(translation_index, mod_gum, mod_spa):
32
+ # transform index to id
33
+ # submit to api
34
+ translation = translations[translation_index]
35
+ request = {
36
+ "data": {
37
+ "key": {
38
+ "translation_timestamp": translation[3],
39
+ "is_checked": "False"
40
+ },
41
+ "new_values": {
42
+ "is_checked": "True",
43
+ "gum": mod_gum,
44
+ "es": translation[2], #TODO: next version
45
+ }
46
+ }
47
+ }
48
+ response = requests.post(API_URL_UPDATE, json=request)
49
+ response.json()
50
+
51
+ return "Traducción corregida" if response.status_code == 200 else "Error del servicio"
52
 
53
  # Interface Components
54
  with gr.Blocks() as demo:
55
+ translations_dataset_input = gr.Dataset(components=[gr.Textbox(visible=False)],#, gr.Textbox(visible=False)],
56
 
57
  label="Traducciones",
58
  samples=translations,
 
60
  samples_per_page=10
61
  )
62
  gum_keyboard_textbox_input = KeyboardTextBoxComponent(#value=translations[selected_translation_index][0],
63
+ label="Al Namuy Wam (Namtrik)",
64
  #info="Elige las traducciones que desees revisar"
65
  )
66
+ spa_textbox_input = gr.Textbox(label="Del Español", interactive=False)
67
  # Interactions
68
  def assign_trasnlation_id(evt: gr.SelectData):
69
  # selected_translation_index = evt.index
70
+ return translations[evt.index][1], translations[evt.index][2]
71
+ translations_dataset_input.select(fn=assign_trasnlation_id, outputs=[gum_keyboard_textbox_input,spa_textbox_input])
 
72
 
73
  # Interface
74
  gr.Interface(
75
  translation_chat_fn,
76
  [
77
  translations_dataset_input,
78
+ spa_textbox_input,
79
  gum_keyboard_textbox_input,
80
  ],
81
  "text",
src/demo/app.py CHANGED
@@ -4,20 +4,11 @@ from gradio_keyboardtextboxcomponent import KeyboardTextBoxComponent
4
  import json
5
  import requests
6
 
7
- API_URL_LIST = "https://jsonplaceholder.typicode.com/todos"
 
8
 
9
  # Una aplicación con un listado de traducciones pendientes
10
  # presionar sobre una
11
- def translation_chat_fn(translation_index, modification):
12
- # transform index to id
13
- # submit to api
14
-
15
- response = requests.get(API_URL_LIST) # TODO: Post
16
- response.json()
17
- print(response.json())
18
-
19
- api_response = True
20
- return "Traducción corregida" if api_response else "Error del servicio"
21
 
22
  selected_translation_index = 0
23
 
@@ -25,12 +16,43 @@ selected_translation_index = 0
25
  # {"id": 0, "text_spa": "The quick brown fox jumps over the lazy dog", "text_gum": "El rápido zorro café salta sobre los perezosos perros"},
26
  # {"id": 1, "text_spa": "Build & share delightful machine learning apps", "text_gum": "Construye y comparte encantadoras aplicaciones de aprendizaje de máquina"},
27
  # ]
28
- translations_response = requests.get(API_URL_LIST).json() # TODO: Post
29
- translations = list(map(lambda x: [x["title"]], translations_response))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  # Interface Components
32
  with gr.Blocks() as demo:
33
- translations_dataset_input = gr.Dataset(components=[gr.Textbox(visible=False)],# gr.Textbox(visible=False)],
34
 
35
  label="Traducciones",
36
  samples=translations,
@@ -38,22 +60,22 @@ with gr.Blocks() as demo:
38
  samples_per_page=10
39
  )
40
  gum_keyboard_textbox_input = KeyboardTextBoxComponent(#value=translations[selected_translation_index][0],
41
- label="Traducciones",
42
  #info="Elige las traducciones que desees revisar"
43
  )
44
-
45
  # Interactions
46
  def assign_trasnlation_id(evt: gr.SelectData):
47
  # selected_translation_index = evt.index
48
- # print(evt)
49
- return translations[evt.index][0]
50
- translations_dataset_input.select(fn=assign_trasnlation_id, outputs=[gum_keyboard_textbox_input])
51
 
52
  # Interface
53
  gr.Interface(
54
  translation_chat_fn,
55
  [
56
  translations_dataset_input,
 
57
  gum_keyboard_textbox_input,
58
  ],
59
  "text",
 
4
  import json
5
  import requests
6
 
7
+ API_URL_LIST = "https://2xp1wr4k54.execute-api.us-east-1.amazonaws.com/dev/v1/translations/index"
8
+ API_URL_UPDATE = "https://2xp1wr4k54.execute-api.us-east-1.amazonaws.com/dev/v1/translations/update"
9
 
10
  # Una aplicación con un listado de traducciones pendientes
11
  # presionar sobre una
 
 
 
 
 
 
 
 
 
 
12
 
13
  selected_translation_index = 0
14
 
 
16
  # {"id": 0, "text_spa": "The quick brown fox jumps over the lazy dog", "text_gum": "El rápido zorro café salta sobre los perezosos perros"},
17
  # {"id": 1, "text_spa": "Build & share delightful machine learning apps", "text_gum": "Construye y comparte encantadoras aplicaciones de aprendizaje de máquina"},
18
  # ]
19
+ request = {
20
+ "data": {
21
+ "per_page": 10
22
+ }
23
+ }
24
+ translations_response = requests.post(API_URL_LIST, json=request)
25
+ #json.loads(str(response["Item"]).replace("'", '"').encode('utf-8'))
26
+ translations_response=json.loads(json.dumps(translations_response.json()).replace("'", '"').encode('utf-8'))["records"]
27
+ translations = list(map(lambda x: [f'{x["gum"]} : {x["es"]}', x["gum"], x["es"], x["translation_timestamp"]], translations_response))
28
+
29
+ # print(translations)
30
+
31
+ def translation_chat_fn(translation_index, mod_gum, mod_spa):
32
+ # transform index to id
33
+ # submit to api
34
+ translation = translations[translation_index]
35
+ request = {
36
+ "data": {
37
+ "key": {
38
+ "translation_timestamp": translation[3],
39
+ "is_checked": "False"
40
+ },
41
+ "new_values": {
42
+ "is_checked": "True",
43
+ "gum": mod_gum,
44
+ "es": translation[2], #TODO: next version
45
+ }
46
+ }
47
+ }
48
+ response = requests.post(API_URL_UPDATE, json=request)
49
+ response.json()
50
+
51
+ return "Traducción corregida" if response.status_code == 200 else "Error del servicio"
52
 
53
  # Interface Components
54
  with gr.Blocks() as demo:
55
+ translations_dataset_input = gr.Dataset(components=[gr.Textbox(visible=False)],#, gr.Textbox(visible=False)],
56
 
57
  label="Traducciones",
58
  samples=translations,
 
60
  samples_per_page=10
61
  )
62
  gum_keyboard_textbox_input = KeyboardTextBoxComponent(#value=translations[selected_translation_index][0],
63
+ label="Al Namuy Wam (Namtrik)",
64
  #info="Elige las traducciones que desees revisar"
65
  )
66
+ spa_textbox_input = gr.Textbox(label="Del Español", interactive=False)
67
  # Interactions
68
  def assign_trasnlation_id(evt: gr.SelectData):
69
  # selected_translation_index = evt.index
70
+ return translations[evt.index][1], translations[evt.index][2]
71
+ translations_dataset_input.select(fn=assign_trasnlation_id, outputs=[gum_keyboard_textbox_input,spa_textbox_input])
 
72
 
73
  # Interface
74
  gr.Interface(
75
  translation_chat_fn,
76
  [
77
  translations_dataset_input,
78
+ spa_textbox_input,
79
  gum_keyboard_textbox_input,
80
  ],
81
  "text",
src/pyproject.toml CHANGED
@@ -43,7 +43,7 @@ classifiers = [
43
  dev = ["build", "twine"]
44
 
45
  [tool.hatch.build]
46
- artifacts = ["/backend/gradio_keyboardtextboxcomponent/templates", "*.pyi", "backend/gradio_keyboardtextboxcomponent/templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates"]
47
 
48
  [tool.hatch.build.targets.wheel]
49
  packages = ["/backend/gradio_keyboardtextboxcomponent"]
 
43
  dev = ["build", "twine"]
44
 
45
  [tool.hatch.build]
46
+ artifacts = ["/backend/gradio_keyboardtextboxcomponent/templates", "*.pyi", "backend/gradio_keyboardtextboxcomponent/templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates", "\\backend\\gradio_keyboardtextboxcomponent\\templates"]
47
 
48
  [tool.hatch.build.targets.wheel]
49
  packages = ["/backend/gradio_keyboardtextboxcomponent"]