asalhi85 commited on
Commit
1b3279e
1 Parent(s): 1bfbdd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -26,6 +26,25 @@ DUPLICATE = """
26
 
27
  IMAGE_WIDTH = 512
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  def preprocess_stop_sequences(stop_sequences: str) -> Optional[List[str]]:
31
  if not stop_sequences:
@@ -40,7 +59,7 @@ def preprocess_image(image: Image.Image) -> Optional[Image.Image]:
40
 
41
  def user(text_prompt: str, chatbot: List[Tuple[str, str]]):
42
  return "", chatbot + [[text_prompt, None]]
43
-
44
 
45
  def bot(
46
  google_key: str,
@@ -58,7 +77,8 @@ def bot(
58
  "GOOGLE_API_KEY is not set. "
59
  "Please follow the instructions in the README to set it up.")
60
 
61
- text_prompt = chatbot[-1][0]
 
62
  genai.configure(api_key=google_key)
63
  generation_config = genai.types.GenerationConfig(
64
  temperature=temperature,
 
26
 
27
  IMAGE_WIDTH = 512
28
 
29
+ def extract_text_from(vid_link):
30
+ video_url = vid_link
31
+ yt = YouTube(video_url)
32
+ text = ""
33
+ audio_stream = yt.streams.get_audio_only()
34
+ audio_stream.download(filename='tmp.mp4')
35
+ audio_clip = AudioFileClip('tmp.mp4')
36
+ audio_clip.write_audiofile('tmp.wav')
37
+ r = sr.Recognizer()
38
+ with sr.AudioFile('tmp.wav') as source:
39
+ audio_data = r.record(source)
40
+ try:
41
+ text = r.recognize_google(audio_data, language='ar')
42
+ except sr.UnknownValueError:
43
+ print("Google Speech Recognition could not understand audio")
44
+ except sr.RequestError as e:
45
+ print("Could not request results from Google Speech Recognition service; {0}".format(e))
46
+ return text
47
+
48
 
49
  def preprocess_stop_sequences(stop_sequences: str) -> Optional[List[str]]:
50
  if not stop_sequences:
 
59
 
60
  def user(text_prompt: str, chatbot: List[Tuple[str, str]]):
61
  return "", chatbot + [[text_prompt, None]]
62
+ #https://www.youtube.com/watch?v=5Abk7EU5EJI
63
 
64
  def bot(
65
  google_key: str,
 
77
  "GOOGLE_API_KEY is not set. "
78
  "Please follow the instructions in the README to set it up.")
79
 
80
+ #text_prompt = chatbot[-1][0]
81
+ text_prompt = extract_text_from("https://www.youtube.com/watch?v=5Abk7EU5EJI")
82
  genai.configure(api_key=google_key)
83
  generation_config = genai.types.GenerationConfig(
84
  temperature=temperature,