yumyeom commited on
Commit
cf32bd5
โ€ข
1 Parent(s): 11e672e

Create app.py

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. .ipynb_checkpoints/app-checkpoint.py +49 -0
  3. app.py +49 -0
  4. requirements.txt +89 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ env/
.ipynb_checkpoints/app-checkpoint.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gaepago model V1 (CPU Test)
2
+
3
+ # import package
4
+ from transformers import AutoModelForAudioClassification
5
+ from transformers import AutoFeatureExtractor
6
+ from transformers import pipeline
7
+ import gradio as gr
8
+ import torch
9
+
10
+ # Set model & Dataset NM
11
+ MODEL_NAME = "Gae8J/gaepago-20"
12
+ DATASET_NAME = "Gae8J/modeling_v1"
13
+
14
+ # Import Model & feature extractor
15
+ model = AutoModelForAudioClassification.from_pretrained(MODEL_NAME)
16
+ feature_extractor = AutoFeatureExtractor.from_pretrained(MODEL_NAME)
17
+
18
+ # ๋ชจ๋ธ cpu๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์ง„ํ–‰
19
+ model.to("cpu")
20
+
21
+ # Gaepago Inference Model function
22
+ def gaepago_fn(tmp_audio_dir):
23
+ print(tmp_audio_dir)
24
+ audio_dataset = Dataset.from_dict({"audio": [tmp_audio_dir]}).cast_column("audio", Audio(sampling_rate=16000))
25
+ inputs = feature_extractor(audio_dataset[0]["audio"]["array"]
26
+ ,sampling_rate=audio_dataset[0]["audio"]["sampling_rate"]
27
+ ,return_tensors="pt")
28
+ with torch.no_grad():
29
+ logits = model(**inputs).logits
30
+ predicted_class_ids = torch.argmax(logits).item()
31
+ predicted_label = model.config.id2label[predicted_class_ids]
32
+
33
+ return predicted_label
34
+
35
+ # Main
36
+ main_api = gr.Blocks()
37
+
38
+ with demo:
39
+ gr.Markdown("## 8J Gaepago Demo(with CPU)")
40
+ with gr.Row():
41
+ audio = gr.Audio(source="microphone", type="filepath"
42
+ ,label='๋…น์Œ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ดˆ์ฝ”๊ฐ€ ํ•˜๋Š” ๋ง์„ ๋“ค๋ ค์ฃผ์„ธ์š”')
43
+ transcription = gr.Textbox(label='์ง€๊ธˆ ์ดˆ์ฝ”๊ฐ€ ํ•˜๋Š” ๋ง์€...')
44
+ b1 = gr.Button("๊ฐ•์•„์ง€ ์–ธ์–ด ๋ฒˆ์—ญ!")
45
+
46
+ b1.click(gaepago_fn, inputs=audio, outputs=transcription)
47
+ examples = gr.Examples(examples=example_list,
48
+ inputs=[audio])
49
+ main_api.launch(share=True)
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gaepago model V1 (CPU Test)
2
+
3
+ # import package
4
+ from transformers import AutoModelForAudioClassification
5
+ from transformers import AutoFeatureExtractor
6
+ from transformers import pipeline
7
+ import gradio as gr
8
+ import torch
9
+
10
+ # Set model & Dataset NM
11
+ MODEL_NAME = "Gae8J/gaepago-20"
12
+ DATASET_NAME = "Gae8J/modeling_v1"
13
+
14
+ # Import Model & feature extractor
15
+ model = AutoModelForAudioClassification.from_pretrained(MODEL_NAME)
16
+ feature_extractor = AutoFeatureExtractor.from_pretrained(MODEL_NAME)
17
+
18
+ # ๋ชจ๋ธ cpu๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์ง„ํ–‰
19
+ model.to("cpu")
20
+
21
+ # Gaepago Inference Model function
22
+ def gaepago_fn(tmp_audio_dir):
23
+ print(tmp_audio_dir)
24
+ audio_dataset = Dataset.from_dict({"audio": [tmp_audio_dir]}).cast_column("audio", Audio(sampling_rate=16000))
25
+ inputs = feature_extractor(audio_dataset[0]["audio"]["array"]
26
+ ,sampling_rate=audio_dataset[0]["audio"]["sampling_rate"]
27
+ ,return_tensors="pt")
28
+ with torch.no_grad():
29
+ logits = model(**inputs).logits
30
+ predicted_class_ids = torch.argmax(logits).item()
31
+ predicted_label = model.config.id2label[predicted_class_ids]
32
+
33
+ return predicted_label
34
+
35
+ # Main
36
+ main_api = gr.Blocks()
37
+
38
+ with demo:
39
+ gr.Markdown("## 8J Gaepago Demo(with CPU)")
40
+ with gr.Row():
41
+ audio = gr.Audio(source="microphone", type="filepath"
42
+ ,label='๋…น์Œ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ดˆ์ฝ”๊ฐ€ ํ•˜๋Š” ๋ง์„ ๋“ค๋ ค์ฃผ์„ธ์š”')
43
+ transcription = gr.Textbox(label='์ง€๊ธˆ ์ดˆ์ฝ”๊ฐ€ ํ•˜๋Š” ๋ง์€...')
44
+ b1 = gr.Button("๊ฐ•์•„์ง€ ์–ธ์–ด ๋ฒˆ์—ญ!")
45
+
46
+ b1.click(gaepago_fn, inputs=audio, outputs=transcription)
47
+ examples = gr.Examples(examples=example_list,
48
+ inputs=[audio])
49
+ main_api.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.1.0
2
+ aiohttp==3.8.4
3
+ aiosignal==1.3.1
4
+ altair==5.0.1
5
+ anyio==3.7.0
6
+ async-timeout==4.0.2
7
+ attrs==23.1.0
8
+ certifi==2023.5.7
9
+ charset-normalizer==3.1.0
10
+ click==8.1.3
11
+ cmake==3.26.4
12
+ contourpy==1.1.0
13
+ cycler==0.11.0
14
+ exceptiongroup==1.1.1
15
+ fastapi==0.97.0
16
+ ffmpy==0.3.0
17
+ filelock==3.12.2
18
+ fonttools==4.40.0
19
+ frozenlist==1.3.3
20
+ fsspec==2023.6.0
21
+ gradio==3.35.2
22
+ gradio_client==0.2.7
23
+ h11==0.14.0
24
+ httpcore==0.17.2
25
+ httpx==0.24.1
26
+ huggingface-hub==0.15.1
27
+ idna==3.4
28
+ importlib-resources==5.12.0
29
+ Jinja2==3.1.2
30
+ jsonschema==4.17.3
31
+ kiwisolver==1.4.4
32
+ linkify-it-py==2.0.2
33
+ lit==16.0.6
34
+ markdown-it-py==2.2.0
35
+ MarkupSafe==2.1.3
36
+ matplotlib==3.7.1
37
+ mdit-py-plugins==0.3.3
38
+ mdurl==0.1.2
39
+ mpmath==1.3.0
40
+ multidict==6.0.4
41
+ networkx==3.1
42
+ numpy==1.24.3
43
+ nvidia-cublas-cu11==11.10.3.66
44
+ nvidia-cuda-cupti-cu11==11.7.101
45
+ nvidia-cuda-nvrtc-cu11==11.7.99
46
+ nvidia-cuda-runtime-cu11==11.7.99
47
+ nvidia-cudnn-cu11==8.5.0.96
48
+ nvidia-cufft-cu11==10.9.0.58
49
+ nvidia-curand-cu11==10.2.10.91
50
+ nvidia-cusolver-cu11==11.4.0.1
51
+ nvidia-cusparse-cu11==11.7.4.91
52
+ nvidia-nccl-cu11==2.14.3
53
+ nvidia-nvtx-cu11==11.7.91
54
+ orjson==3.9.1
55
+ packaging==23.1
56
+ pandas==2.0.2
57
+ Pillow==9.5.0
58
+ pkgutil_resolve_name==1.3.10
59
+ pydantic==1.10.9
60
+ pydub==0.25.1
61
+ Pygments==2.15.1
62
+ pyparsing==3.1.0
63
+ pyrsistent==0.19.3
64
+ python-dateutil==2.8.2
65
+ python-multipart==0.0.6
66
+ pytz==2023.3
67
+ PyYAML==6.0
68
+ regex==2023.6.3
69
+ requests==2.31.0
70
+ safetensors==0.3.1
71
+ semantic-version==2.10.0
72
+ six==1.16.0
73
+ sniffio==1.3.0
74
+ starlette==0.27.0
75
+ sympy==1.12
76
+ tokenizers==0.13.3
77
+ toolz==0.12.0
78
+ torch==2.0.1
79
+ tqdm==4.65.0
80
+ transformers==4.30.2
81
+ triton==2.0.0
82
+ typing_extensions==4.6.3
83
+ tzdata==2023.3
84
+ uc-micro-py==1.0.2
85
+ urllib3==2.0.3
86
+ uvicorn==0.22.0
87
+ websockets==11.0.3
88
+ yarl==1.9.2
89
+ zipp==3.15.0