Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,5 @@
|
|
1 |
import openai
|
2 |
import gradio as gr
|
3 |
-
from pytube import YouTube
|
4 |
-
from youtube_dl import YoutubeDL
|
5 |
-
import yt_dlp
|
6 |
import os
|
7 |
from pydub import AudioSegment
|
8 |
import time
|
@@ -138,34 +135,6 @@ def speech_2_text(audio,api_key, context=[]):
|
|
138 |
|
139 |
return responses, context
|
140 |
|
141 |
-
def get_audio(url,api_key,context=[]):
|
142 |
-
openai.api_key = api_key
|
143 |
-
destination = f"./audio/test"
|
144 |
-
try:
|
145 |
-
ydl_opts = {
|
146 |
-
'format': 'bestaudio/best',
|
147 |
-
'outtmpl':destination,
|
148 |
-
'postprocessors': [{
|
149 |
-
'key': 'FFmpegExtractAudio',
|
150 |
-
'preferredcodec': 'mp3',
|
151 |
-
'preferredquality': '192',
|
152 |
-
}],
|
153 |
-
}
|
154 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
155 |
-
ydl.download([url])
|
156 |
-
|
157 |
-
audio_file= open(f'{destination}.mp3', "rb")
|
158 |
-
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
159 |
-
|
160 |
-
context += [transcript.text]
|
161 |
-
|
162 |
-
responses = [(u,b) for u,b in zip(context[::2], context[1::2])]
|
163 |
-
|
164 |
-
return responses, context
|
165 |
-
|
166 |
-
except Exception as e:
|
167 |
-
print("Connection Error")
|
168 |
-
|
169 |
|
170 |
with gr.Blocks(css="#chatbot {overflow-y:auto; min-height:400px;} ") as dialog_app:
|
171 |
|
|
|
1 |
import openai
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
import os
|
4 |
from pydub import AudioSegment
|
5 |
import time
|
|
|
135 |
|
136 |
return responses, context
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
with gr.Blocks(css="#chatbot {overflow-y:auto; min-height:400px;} ") as dialog_app:
|
140 |
|