aymonc commited on
Commit
990de2d
·
1 Parent(s): 2f68324

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +107 -0
  2. requirements.txt +112 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # %%
2
+ #%pip install transformers
3
+ #%pip install torch
4
+ #%pip install torchaudio
5
+ #%pip install fuzzywuzzy
6
+ #%pip install pdfkit
7
+ #%pip install jinja2
8
+ #%pip install wkhtmltopdf
9
+
10
+
11
+ # %%
12
+ import gradio as gr
13
+ from transformers import pipeline
14
+ import numpy as np
15
+ import string
16
+ from fuzzywuzzy import fuzz
17
+
18
+
19
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
20
+
21
+ with gr.Blocks() as demo:
22
+
23
+ def welcome(rank, name):
24
+ global g_rank
25
+ global g_name
26
+ g_rank = rank
27
+ g_name = name
28
+ welcome_message= "## Welcome "+rank+" "+name+"!"
29
+ return {welcome_message_markdown: gr.Markdown(value=welcome_message, visible=True), welcome_inputs_col: gr.Column(visible=False), section_1_col: gr.Column(visible = True)}
30
+
31
+ def transcribe(audio):
32
+ global g_result_clean
33
+ sr, y = audio
34
+ y = y.astype(np.float32)
35
+ y /= np.max(np.abs(y))
36
+ result = transcriber({"sampling_rate": sr, "raw": y})["text"]
37
+ # Create a translation table to remove punctuation
38
+ translator = str.maketrans('', '', string.punctuation)
39
+ # Remove punctuation and convert to lowercase
40
+ result_clean = result.translate(translator).lower()
41
+ g_result_clean = result_clean
42
+ return result_clean
43
+
44
+ def check_answer():
45
+ global g_result_clean
46
+ similarity_ratio = fuzz.ratio(g_result_clean, " hello zero this is two charlie radio check over")
47
+ if similarity_ratio >= 90:
48
+ return {right_answer: gr.Markdown("# Congratulations! You have passed this E-learning course", visible = True), wrong_answer: gr.Markdown(" That isn't quite right. Please try again.", visible = False), section_1_practise_col: gr.Column(visible = False), section_1_col: gr.Column(visible = False)}
49
+ else:
50
+ return {right_answer: gr.Markdown("# Congratulations! You have passed this E-learning course", visible = False), wrong_answer: gr.Markdown(" That isn't quite right. Please try again.", visible = True)}
51
+
52
+ def practise_col():
53
+ return {section_1_practise_col: gr.Column(visible = True), next_button_3: gr.Button("Practise", visible=False)}
54
+
55
+ gr.Markdown("# Communications ITR E-learning Demonstrator")
56
+ with gr.Column() as welcome_inputs_col:
57
+ gr.Markdown("""Welcome to the Communications ITR E-learning.
58
+ Please complete the following details so that your ITR can be signed off.""")
59
+ #Should add validation for these inputs for product. See https://www.gradio.app/guides/controlling-layout#visibility for an example of this
60
+ name_box = gr.Textbox(label="Name")
61
+ #name_error_box = gr.Textbox(label="Error", visible=False)
62
+ rank_box = gr.Textbox(label="Rank")
63
+ number_box = gr.Textbox(label="Number")
64
+ next_button = gr.Button("Submit")
65
+ welcome_message_markdown= gr.Markdown("Placeholder", visible = False)
66
+
67
+
68
+ with gr.Column(visible = False) as section_1_col:
69
+ gr.Markdown("## Establish communications (TO 14.1.1)")
70
+ gr.Markdown("### Calling Transmission")
71
+ gr.Markdown("#### Initial Call")
72
+ gr.Markdown("Unlike mobile phones, radios transmit onto a frequency (or range of frequencies) where anyone listening can hear. Similarly, they also do not transmit the caller ID. For this reason, when establishing communications it is important to first make an inital call as part of your message, which tells the net (everyone listening) who you wish to talk to, and who is talking:")
73
+ gr.Markdown("""HELLO \<callsign I wish to contact> THIS IS \<my own callsign>""")
74
+ gr.Markdown("Example: HELLO 0 THIS IS 1C")
75
+ gr.Markdown("#### Message Text")
76
+ gr.Markdown("Now that we have let the net know who we are and who we want to talk to, we can now send our message information. We will go into this in more detail later in this E-learning package.")
77
+ gr.Markdown("#### Ending")
78
+ gr.Markdown("""This will always be one of the following:
79
+ 1. OUT - meaning ‘This is the end of my transmission to you and no answer is required or expected’. OUT should be used whenever possible.
80
+ 2. OVER - meaning ‘This is the end of my transmission to you and a response is necessary. Go ahead and transmit’.
81
+ 3. OUT TO YOU - meaning ‘This is the end of my transmission and no answer is required or expected. A transmission to another station follows immediately’.""")
82
+ gr.Markdown("#### Together")
83
+ gr.Markdown("""These three parts together form the whole transmission as below:""")
84
+ gr.Markdown(""" Format: Initial call - Message text - Ending
85
+ Example: HELLO 1D THIS IS 3C, message to send, OVER""")
86
+ next_button_3 = gr.Button("Practise")
87
+ with gr.Column(visible = False) as section_1_practise_col:
88
+ gr.Markdown("### Practice:")
89
+ gr.Markdown("""Your callsign is: 2C (2- CHARLIE) and you wish to talk to 0 (ZERO). Your message to send is: "radio check", and you want a reply to your message so the message ending is "OVER". """)
90
+ gr.Interface(transcribe,gr.Audio(sources=["microphone"]), "text")
91
+
92
+ next_button_2 = gr.Button("Check Answer")
93
+ wrong_answer = gr.Markdown(" That isn't quite right. Please try again.", visible = False)
94
+ right_answer = gr.Markdown("# Congratulations! You have passed this E-learning course", visible = False)
95
+ next_button.click(welcome, [rank_box, name_box], [welcome_message_markdown, welcome_inputs_col, section_1_col])
96
+ next_button_2.click(check_answer, [], [wrong_answer, right_answer, section_1_practise_col, section_1_col])
97
+ next_button_3.click(practise_col, [], [section_1_practise_col, next_button_3])
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+ demo.launch(debug=True, show_api=False)
106
+
107
+
requirements.txt ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ aiohttp==3.8.6
3
+ aiosignal==1.3.1
4
+ altair==5.1.2
5
+ annotated-types==0.6.0
6
+ anyio==3.7.1
7
+ appnope==0.1.3
8
+ asttokens==2.4.1
9
+ async-timeout==4.0.3
10
+ attrs==23.1.0
11
+ certifi==2023.7.22
12
+ charset-normalizer==3.3.2
13
+ click==8.1.7
14
+ colorama==0.4.6
15
+ comm==0.2.0
16
+ contourpy==1.2.0
17
+ cycler==0.12.1
18
+ dataclasses-json==0.6.1
19
+ debugpy==1.8.0
20
+ decorator==5.1.1
21
+ distro==1.8.0
22
+ executing==2.0.1
23
+ faiss-cpu==1.7.4
24
+ fastapi==0.104.1
25
+ ffmpy==0.3.1
26
+ filelock==3.13.1
27
+ fonttools==4.44.0
28
+ frozenlist==1.4.0
29
+ fsspec==2023.10.0
30
+ gradio==4.1.1
31
+ gradio_client==0.7.0
32
+ h11==0.14.0
33
+ httpcore==1.0.1
34
+ httpx==0.25.1
35
+ huggingface-hub==0.18.0
36
+ idna==3.4
37
+ importlib-resources==6.1.1
38
+ ipykernel==6.26.0
39
+ ipython==8.17.2
40
+ jedi==0.19.1
41
+ Jinja2==3.1.2
42
+ jsonpatch==1.33
43
+ jsonpointer==2.4
44
+ jsonschema==4.19.2
45
+ jsonschema-specifications==2023.7.1
46
+ jupyter_client==8.6.0
47
+ jupyter_core==5.5.0
48
+ kiwisolver==1.4.5
49
+ langchain==0.0.330
50
+ langsmith==0.0.60
51
+ markdown-it-py==3.0.0
52
+ MarkupSafe==2.1.3
53
+ marshmallow==3.20.1
54
+ matplotlib==3.8.1
55
+ matplotlib-inline==0.1.6
56
+ mdurl==0.1.2
57
+ multidict==6.0.4
58
+ mypy-extensions==1.0.0
59
+ nest-asyncio==1.5.8
60
+ numpy==1.26.1
61
+ openai==0.28.1
62
+ orjson==3.9.10
63
+ packaging==23.2
64
+ pandas==2.1.2
65
+ parso==0.8.3
66
+ pexpect==4.8.0
67
+ Pillow==10.1.0
68
+ pip==23.3.1
69
+ platformdirs==3.11.0
70
+ prompt-toolkit==3.0.39
71
+ psutil==5.9.6
72
+ ptyprocess==0.7.0
73
+ pure-eval==0.2.2
74
+ pydantic==2.4.2
75
+ pydantic_core==2.10.1
76
+ pydub==0.25.1
77
+ Pygments==2.16.1
78
+ pyparsing==3.1.1
79
+ python-dateutil==2.8.2
80
+ python-multipart==0.0.6
81
+ pytz==2023.3.post1
82
+ PyYAML==6.0.1
83
+ pyzmq==25.1.1
84
+ referencing==0.30.2
85
+ regex==2023.10.3
86
+ requests==2.31.0
87
+ rich==13.6.0
88
+ rpds-py==0.12.0
89
+ semantic-version==2.10.0
90
+ setuptools==65.5.0
91
+ shellingham==1.5.4
92
+ six==1.16.0
93
+ sniffio==1.3.0
94
+ SQLAlchemy==2.0.23
95
+ stack-data==0.6.3
96
+ starlette==0.27.0
97
+ tenacity==8.2.3
98
+ tiktoken==0.5.1
99
+ tomlkit==0.12.0
100
+ toolz==0.12.0
101
+ tornado==6.3.3
102
+ tqdm==4.66.1
103
+ traitlets==5.13.0
104
+ typer==0.9.0
105
+ typing_extensions==4.8.0
106
+ typing-inspect==0.9.0
107
+ tzdata==2023.3
108
+ urllib3==2.0.7
109
+ uvicorn==0.24.0.post1
110
+ wcwidth==0.2.9
111
+ websockets==11.0.3
112
+ yarl==1.9.2