Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -25,7 +25,7 @@ pipe = pipeline( 
     | 
|
| 25 | 
         | 
| 26 | 
         
             
            def transcribe(inputs, task):
         
     | 
| 27 | 
         
             
                if inputs is None:
         
     | 
| 28 | 
         
            -
                    raise gr.Error(" 
     | 
| 29 | 
         | 
| 30 | 
         
             
                text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
         
     | 
| 31 | 
         
             
                return  text
         
     | 
| 
         @@ -41,29 +41,29 @@ def _return_yt_html_embed(yt_url): 
     | 
|
| 41 | 
         | 
| 42 | 
         
             
            def download_yt_audio(yt_url, filename):
         
     | 
| 43 | 
         
             
                info_loader = youtube_dl.YoutubeDL()
         
     | 
| 44 | 
         
            -
             
     | 
| 45 | 
         
             
                try:
         
     | 
| 46 | 
         
             
                    info = info_loader.extract_info(yt_url, download=False)
         
     | 
| 47 | 
         
             
                except youtube_dl.utils.DownloadError as err:
         
     | 
| 48 | 
         
             
                    raise gr.Error(str(err))
         
     | 
| 49 | 
         
            -
             
     | 
| 50 | 
         
             
                file_length = info["duration_string"]
         
     | 
| 51 | 
         
             
                file_h_m_s = file_length.split(":")
         
     | 
| 52 | 
         
             
                file_h_m_s = [int(sub_length) for sub_length in file_h_m_s]
         
     | 
| 53 | 
         
            -
             
     | 
| 54 | 
         
             
                if len(file_h_m_s) == 1:
         
     | 
| 55 | 
         
             
                    file_h_m_s.insert(0, 0)
         
     | 
| 56 | 
         
             
                if len(file_h_m_s) == 2:
         
     | 
| 57 | 
         
             
                    file_h_m_s.insert(0, 0)
         
     | 
| 58 | 
         
             
                file_length_s = file_h_m_s[0] * 3600 + file_h_m_s[1] * 60 + file_h_m_s[2]
         
     | 
| 59 | 
         
            -
             
     | 
| 60 | 
         
             
                if file_length_s > YT_LENGTH_LIMIT_S:
         
     | 
| 61 | 
         
             
                    yt_length_limit_hms = time.strftime("%HH:%MM:%SS", time.gmtime(YT_LENGTH_LIMIT_S))
         
     | 
| 62 | 
         
             
                    file_length_hms = time.strftime("%HH:%MM:%SS", time.gmtime(file_length_s))
         
     | 
| 63 | 
         
            -
                    raise gr.Error(f" 
     | 
| 64 | 
         
            -
             
     | 
| 65 | 
         
             
                ydl_opts = {"outtmpl": filename, "format": "worstvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"}
         
     | 
| 66 | 
         
            -
             
     | 
| 67 | 
         
             
                with youtube_dl.YoutubeDL(ydl_opts) as ydl:
         
     | 
| 68 | 
         
             
                    try:
         
     | 
| 69 | 
         
             
                        ydl.download([yt_url])
         
     | 
| 
         @@ -99,40 +99,46 @@ mf_transcribe = gr.Interface( 
     | 
|
| 99 | 
         
             
                outputs="text",
         
     | 
| 100 | 
         
             
                layout="horizontal",
         
     | 
| 101 | 
         
             
                theme="huggingface",
         
     | 
| 102 | 
         
            -
                title="Whisper Large V3  
     | 
| 103 | 
         
            -
                description= 
     | 
| 
         | 
|
| 
         | 
|
| 104 | 
         
             
                allow_flagging="never",
         
     | 
| 105 | 
         
             
            )
         
     | 
| 106 | 
         | 
| 107 | 
         
             
            file_transcribe = gr.Interface(
         
     | 
| 108 | 
         
             
                fn=transcribe,
         
     | 
| 109 | 
         
             
                inputs=[
         
     | 
| 110 | 
         
            -
                    gr.inputs.Audio(source="upload", type="filepath", optional=True, label="Audio  
     | 
| 111 | 
         
             
                    gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
         
     | 
| 112 | 
         
             
                ],
         
     | 
| 113 | 
         
             
                outputs="text",
         
     | 
| 114 | 
         
             
                layout="horizontal",
         
     | 
| 115 | 
         
             
                theme="huggingface",
         
     | 
| 116 | 
         
            -
                title="Whisper Large V3  
     | 
| 117 | 
         
            -
                description= 
     | 
| 
         | 
|
| 
         | 
|
| 118 | 
         
             
                allow_flagging="never",
         
     | 
| 119 | 
         
             
            )
         
     | 
| 120 | 
         | 
| 121 | 
         
             
            yt_transcribe = gr.Interface(
         
     | 
| 122 | 
         
             
                fn=yt_transcribe,
         
     | 
| 123 | 
         
             
                inputs=[
         
     | 
| 124 | 
         
            -
                    gr.inputs.Textbox(lines=1, placeholder=" 
     | 
| 125 | 
         
             
                    gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe")
         
     | 
| 126 | 
         
             
                ],
         
     | 
| 127 | 
         
             
                outputs=["html", "text"],
         
     | 
| 128 | 
         
             
                layout="horizontal",
         
     | 
| 129 | 
         
             
                theme="huggingface",
         
     | 
| 130 | 
         
            -
                title="Whisper Large V3  
     | 
| 131 | 
         
            -
                description= 
     | 
| 
         | 
|
| 
         | 
|
| 132 | 
         
             
                allow_flagging="never",
         
     | 
| 133 | 
         
             
            )
         
     | 
| 134 | 
         | 
| 135 | 
         
             
            with demo:
         
     | 
| 136 | 
         
            -
                gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], [" 
     | 
| 137 | 
         | 
| 138 | 
         
             
            demo.launch(enable_queue=True)
         
     | 
| 
         | 
|
| 25 | 
         | 
| 26 | 
         
             
            def transcribe(inputs, task):
         
     | 
| 27 | 
         
             
                if inputs is None:
         
     | 
| 28 | 
         
            +
                    raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
         
     | 
| 29 | 
         | 
| 30 | 
         
             
                text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
         
     | 
| 31 | 
         
             
                return  text
         
     | 
| 
         | 
|
| 41 | 
         | 
| 42 | 
         
             
            def download_yt_audio(yt_url, filename):
         
     | 
| 43 | 
         
             
                info_loader = youtube_dl.YoutubeDL()
         
     | 
| 44 | 
         
            +
                
         
     | 
| 45 | 
         
             
                try:
         
     | 
| 46 | 
         
             
                    info = info_loader.extract_info(yt_url, download=False)
         
     | 
| 47 | 
         
             
                except youtube_dl.utils.DownloadError as err:
         
     | 
| 48 | 
         
             
                    raise gr.Error(str(err))
         
     | 
| 49 | 
         
            +
                
         
     | 
| 50 | 
         
             
                file_length = info["duration_string"]
         
     | 
| 51 | 
         
             
                file_h_m_s = file_length.split(":")
         
     | 
| 52 | 
         
             
                file_h_m_s = [int(sub_length) for sub_length in file_h_m_s]
         
     | 
| 53 | 
         
            +
                
         
     | 
| 54 | 
         
             
                if len(file_h_m_s) == 1:
         
     | 
| 55 | 
         
             
                    file_h_m_s.insert(0, 0)
         
     | 
| 56 | 
         
             
                if len(file_h_m_s) == 2:
         
     | 
| 57 | 
         
             
                    file_h_m_s.insert(0, 0)
         
     | 
| 58 | 
         
             
                file_length_s = file_h_m_s[0] * 3600 + file_h_m_s[1] * 60 + file_h_m_s[2]
         
     | 
| 59 | 
         
            +
                
         
     | 
| 60 | 
         
             
                if file_length_s > YT_LENGTH_LIMIT_S:
         
     | 
| 61 | 
         
             
                    yt_length_limit_hms = time.strftime("%HH:%MM:%SS", time.gmtime(YT_LENGTH_LIMIT_S))
         
     | 
| 62 | 
         
             
                    file_length_hms = time.strftime("%HH:%MM:%SS", time.gmtime(file_length_s))
         
     | 
| 63 | 
         
            +
                    raise gr.Error(f"Maximum YouTube length is {yt_length_limit_hms}, got {file_length_hms} YouTube video.")
         
     | 
| 64 | 
         
            +
                
         
     | 
| 65 | 
         
             
                ydl_opts = {"outtmpl": filename, "format": "worstvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"}
         
     | 
| 66 | 
         
            +
                
         
     | 
| 67 | 
         
             
                with youtube_dl.YoutubeDL(ydl_opts) as ydl:
         
     | 
| 68 | 
         
             
                    try:
         
     | 
| 69 | 
         
             
                        ydl.download([yt_url])
         
     | 
| 
         | 
|
| 99 | 
         
             
                outputs="text",
         
     | 
| 100 | 
         
             
                layout="horizontal",
         
     | 
| 101 | 
         
             
                theme="huggingface",
         
     | 
| 102 | 
         
            +
                title="Whisper Large V3: Transcribe Audio",
         
     | 
| 103 | 
         
            +
                description=(
         
     | 
| 104 | 
         
            +
                    "Whisper Large V3 fine-tuned for Uzbek language by Dataprizma"
         
     | 
| 105 | 
         
            +
                ),
         
     | 
| 106 | 
         
             
                allow_flagging="never",
         
     | 
| 107 | 
         
             
            )
         
     | 
| 108 | 
         | 
| 109 | 
         
             
            file_transcribe = gr.Interface(
         
     | 
| 110 | 
         
             
                fn=transcribe,
         
     | 
| 111 | 
         
             
                inputs=[
         
     | 
| 112 | 
         
            +
                    gr.inputs.Audio(source="upload", type="filepath", optional=True, label="Audio file"),
         
     | 
| 113 | 
         
             
                    gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
         
     | 
| 114 | 
         
             
                ],
         
     | 
| 115 | 
         
             
                outputs="text",
         
     | 
| 116 | 
         
             
                layout="horizontal",
         
     | 
| 117 | 
         
             
                theme="huggingface",
         
     | 
| 118 | 
         
            +
                title="Whisper Large V3: Transcribe Audio",
         
     | 
| 119 | 
         
            +
                description=(
         
     | 
| 120 | 
         
            +
                    "Whisper Large V3 fine-tuned for Uzbek language by Dataprizma"
         
     | 
| 121 | 
         
            +
                ),
         
     | 
| 122 | 
         
             
                allow_flagging="never",
         
     | 
| 123 | 
         
             
            )
         
     | 
| 124 | 
         | 
| 125 | 
         
             
            yt_transcribe = gr.Interface(
         
     | 
| 126 | 
         
             
                fn=yt_transcribe,
         
     | 
| 127 | 
         
             
                inputs=[
         
     | 
| 128 | 
         
            +
                    gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
         
     | 
| 129 | 
         
             
                    gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe")
         
     | 
| 130 | 
         
             
                ],
         
     | 
| 131 | 
         
             
                outputs=["html", "text"],
         
     | 
| 132 | 
         
             
                layout="horizontal",
         
     | 
| 133 | 
         
             
                theme="huggingface",
         
     | 
| 134 | 
         
            +
                title="Whisper Large V3: Transcribe YouTube",
         
     | 
| 135 | 
         
            +
                description=(
         
     | 
| 136 | 
         
            +
                    "Whisper Large V3 fine-tuned for Uzbek language by Dataprizma"
         
     | 
| 137 | 
         
            +
                ),
         
     | 
| 138 | 
         
             
                allow_flagging="never",
         
     | 
| 139 | 
         
             
            )
         
     | 
| 140 | 
         | 
| 141 | 
         
             
            with demo:
         
     | 
| 142 | 
         
            +
                gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
         
     | 
| 143 | 
         | 
| 144 | 
         
             
            demo.launch(enable_queue=True)
         
     |