tomaseo2022 commited on
Commit
fcf76e3
·
1 Parent(s): 0748136

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +165 -0
app.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install git+https://github.com/openai/whisper.git")
3
+ import gradio as gr
4
+ import whisper
5
+ from convert import main
6
+
7
+ model = whisper.load_model("small")
8
+
9
+ def inference(audio):
10
+ audio = whisper.load_audio(audio)
11
+ audio = whisper.pad_or_trim(audio)
12
+
13
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
14
+
15
+ _, probs = model.detect_language(mel)
16
+
17
+ options = whisper.DecodingOptions(fp16 = False)
18
+ result = whisper.decode(model, mel, options)
19
+
20
+ print(result.text)
21
+ return result.text
22
+
23
+ def inference2(url):
24
+ return main(url)
25
+
26
+
27
+ title="YouWhisper"
28
+
29
+ description="YouWhisper converts Youtube videos to text using openai/whisper.."
30
+
31
+ css = """
32
+ .gradio-container {
33
+ font-family: 'IBM Plex Sans', sans-serif;
34
+ }
35
+ .gr-button {
36
+ color: white;
37
+ border-color: black;
38
+ background: black;
39
+ }
40
+ input[type='range'] {
41
+ accent-color: black;
42
+ }
43
+ .dark input[type='range'] {
44
+ accent-color: #dfdfdf;
45
+ }
46
+ .container {
47
+ max-width: 730px;
48
+ margin: auto;
49
+ padding-top: 1.5rem;
50
+ }
51
+
52
+ .details:hover {
53
+ text-decoration: underline;
54
+ }
55
+ .gr-button {
56
+ white-space: nowrap;
57
+ }
58
+ .gr-button:focus {
59
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
60
+ outline: none;
61
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
62
+ --tw-border-opacity: 1;
63
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
64
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
65
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
66
+ --tw-ring-opacity: .5;
67
+ }
68
+ .footer {
69
+ margin-bottom: 45px;
70
+ margin-top: 35px;
71
+ text-align: center;
72
+ border-bottom: 1px solid #e5e5e5;
73
+ }
74
+ .footer>p {
75
+ font-size: .8rem;
76
+ display: inline-block;
77
+ padding: 0 10px;
78
+ transform: translateY(10px);
79
+ background: white;
80
+ }
81
+ .dark .footer {
82
+ border-color: #303030;
83
+ }
84
+ .dark .footer>p {
85
+ background: #0b0f19;
86
+ }
87
+ .prompt h4{
88
+ margin: 1.25em 0 .25em 0;
89
+ font-weight: bold;
90
+ font-size: 115%;
91
+ }
92
+ """
93
+
94
+ block = gr.Blocks(css=css)
95
+
96
+ with block:
97
+ gr.HTML(
98
+ """
99
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
100
+ <div
101
+ style="
102
+ display: inline-flex;
103
+ align-items: center;
104
+ gap: 0.8rem;
105
+ font-size: 1.75rem;
106
+ "
107
+ >
108
+ <svg
109
+ width="0.65em"
110
+ height="0.65em"
111
+ viewBox="0 0 115 115"
112
+ fill="none"
113
+ xmlns="http://www.w3.org/2000/svg"
114
+ >
115
+ <rect width="23" height="23" fill="white"></rect>
116
+ <rect y="69" width="23" height="23" fill="white"></rect>
117
+ <rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
118
+ <rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
119
+ <rect x="46" width="23" height="23" fill="white"></rect>
120
+ <rect x="46" y="69" width="23" height="23" fill="white"></rect>
121
+ <rect x="69" width="23" height="23" fill="black"></rect>
122
+ <rect x="69" y="69" width="23" height="23" fill="black"></rect>
123
+ <rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
124
+ <rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
125
+ <rect x="115" y="46" width="23" height="23" fill="white"></rect>
126
+ <rect x="115" y="115" width="23" height="23" fill="white"></rect>
127
+ <rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
128
+ <rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
129
+ <rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
130
+ <rect x="92" y="69" width="23" height="23" fill="white"></rect>
131
+ <rect x="69" y="46" width="23" height="23" fill="white"></rect>
132
+ <rect x="69" y="115" width="23" height="23" fill="white"></rect>
133
+ <rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
134
+ <rect x="46" y="46" width="23" height="23" fill="black"></rect>
135
+ <rect x="46" y="115" width="23" height="23" fill="black"></rect>
136
+ <rect x="46" y="69" width="23" height="23" fill="black"></rect>
137
+ <rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
138
+ <rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
139
+ <rect x="23" y="69" width="23" height="23" fill="black"></rect>
140
+ </svg>
141
+ <h1 style="font-weight: 900; margin-bottom: 7px;">
142
+ YouWhisper
143
+ </h1>
144
+ </div>
145
+ <p>YouWhisper converts Youtube videos to text using openai/whisper..</p>
146
+ </div>
147
+ """
148
+ )
149
+ with gr.Group():
150
+ # add a paragraph to show the details
151
+ gr.HTML(
152
+ """
153
+ <p class="details">
154
+ Enter a Youtube url to convert to text
155
+ </p>
156
+ """
157
+ )
158
+
159
+ # add another textbox to get url from user
160
+ url = gr.Textbox(label="URL", show_label=False, placeholder="Enter Youtube URL")
161
+ btn2 = gr.Button("Transcribe")
162
+ text2 = gr.Textbox(show_label=False, placeholder="Transcription will appear here")
163
+ btn2.click(inference2, inputs=[url], outputs=[text2])
164
+
165
+ block.launch()