Davidmide02 commited on
Commit
5ce4829
1 Parent(s): c461289
Files changed (3) hide show
  1. app.py +18 -0
  2. note.ipynb +103 -0
  3. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ pipe = pipeline(
5
+ "audio-classification", model="Davidmide02/distilhubert-finetuned-gtzan"
6
+ )
7
+
8
+ def classify_audio(filepath):
9
+ preds = pipe(filepath)
10
+ outputs = {}
11
+ for p in preds:
12
+ outputs[p["label"]] = p["score"]
13
+ return outputs
14
+
15
+ demo = gr.Interface(
16
+ fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=gr.Label()
17
+ )
18
+ demo.launch(debug=True)
note.ipynb ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from transformers import pipeline\n",
10
+ "\n",
11
+ "pipe = pipeline(\n",
12
+ " \"audio-classification\", model=\"Davidmide02/distilhubert-finetuned-gtzan\"\n",
13
+ ")"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "def classify_audio(filepath):\n",
23
+ " preds = pipe(filepath)\n",
24
+ " outputs = {}\n",
25
+ " for p in preds:\n",
26
+ " outputs[p[\"label\"]] = p[\"score\"]\n",
27
+ " return outputs"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 4,
33
+ "metadata": {},
34
+ "outputs": [
35
+ {
36
+ "name": "stdout",
37
+ "output_type": "stream",
38
+ "text": [
39
+ "Running on local URL: http://127.0.0.1:7860\n",
40
+ "\n",
41
+ "To create a public link, set `share=True` in `launch()`.\n"
42
+ ]
43
+ },
44
+ {
45
+ "data": {
46
+ "text/html": [
47
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
48
+ ],
49
+ "text/plain": [
50
+ "<IPython.core.display.HTML object>"
51
+ ]
52
+ },
53
+ "metadata": {},
54
+ "output_type": "display_data"
55
+ },
56
+ {
57
+ "name": "stdout",
58
+ "output_type": "stream",
59
+ "text": [
60
+ "Keyboard interruption in main thread... closing server.\n"
61
+ ]
62
+ },
63
+ {
64
+ "data": {
65
+ "text/plain": []
66
+ },
67
+ "execution_count": 4,
68
+ "metadata": {},
69
+ "output_type": "execute_result"
70
+ }
71
+ ],
72
+ "source": [
73
+ "import gradio as gr\n",
74
+ "\n",
75
+ "demo = gr.Interface(\n",
76
+ " fn=classify_audio, inputs=gr.Audio(type=\"filepath\"), outputs=gr.Label()\n",
77
+ ")\n",
78
+ "demo.launch(debug=True)"
79
+ ]
80
+ }
81
+ ],
82
+ "metadata": {
83
+ "kernelspec": {
84
+ "display_name": ".venv",
85
+ "language": "python",
86
+ "name": "python3"
87
+ },
88
+ "language_info": {
89
+ "codemirror_mode": {
90
+ "name": "ipython",
91
+ "version": 3
92
+ },
93
+ "file_extension": ".py",
94
+ "mimetype": "text/x-python",
95
+ "name": "python",
96
+ "nbconvert_exporter": "python",
97
+ "pygments_lexer": "ipython3",
98
+ "version": "3.12.3"
99
+ }
100
+ },
101
+ "nbformat": 4,
102
+ "nbformat_minor": 2
103
+ }
requirements.txt ADDED
Binary file (3.32 kB). View file