Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ def text_to_speech(text):
|
|
| 17 |
# Speech-to-Text function
|
| 18 |
def speech_to_text(audio):
|
| 19 |
recognizer = sr.Recognizer()
|
| 20 |
-
with sr.AudioFile(audio) as source:
|
| 21 |
audio_data = recognizer.record(source)
|
| 22 |
try:
|
| 23 |
text = recognizer.recognize_google(audio_data)
|
|
@@ -39,7 +39,7 @@ def generate_image_description(image):
|
|
| 39 |
|
| 40 |
# Video Description function
|
| 41 |
def generate_video_description(video):
|
| 42 |
-
cap = cv2.VideoCapture(video.name)
|
| 43 |
descriptions = []
|
| 44 |
|
| 45 |
if not cap.isOpened():
|
|
@@ -50,7 +50,6 @@ def generate_video_description(video):
|
|
| 50 |
ret, frame = cap.read()
|
| 51 |
if not ret:
|
| 52 |
break
|
| 53 |
-
# Use a temporary image to generate description
|
| 54 |
image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
| 55 |
description = generate_image_description(image)
|
| 56 |
descriptions.append(description)
|
|
@@ -72,7 +71,7 @@ def main():
|
|
| 72 |
tts_button.click(fn=text_to_speech, inputs=text_input, outputs=tts_output)
|
| 73 |
|
| 74 |
# Speech-to-Text
|
| 75 |
-
stt_input = gr.Audio(
|
| 76 |
stt_button = gr.Button("Convert Speech to Text")
|
| 77 |
stt_output = gr.Textbox(label="Speech-to-Text Output")
|
| 78 |
stt_button.click(fn=speech_to_text, inputs=stt_input, outputs=stt_output)
|
|
|
|
| 17 |
# Speech-to-Text function
|
| 18 |
def speech_to_text(audio):
|
| 19 |
recognizer = sr.Recognizer()
|
| 20 |
+
with sr.AudioFile(audio) as source:
|
| 21 |
audio_data = recognizer.record(source)
|
| 22 |
try:
|
| 23 |
text = recognizer.recognize_google(audio_data)
|
|
|
|
| 39 |
|
| 40 |
# Video Description function
|
| 41 |
def generate_video_description(video):
|
| 42 |
+
cap = cv2.VideoCapture(video.name)
|
| 43 |
descriptions = []
|
| 44 |
|
| 45 |
if not cap.isOpened():
|
|
|
|
| 50 |
ret, frame = cap.read()
|
| 51 |
if not ret:
|
| 52 |
break
|
|
|
|
| 53 |
image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
| 54 |
description = generate_image_description(image)
|
| 55 |
descriptions.append(description)
|
|
|
|
| 71 |
tts_button.click(fn=text_to_speech, inputs=text_input, outputs=tts_output)
|
| 72 |
|
| 73 |
# Speech-to-Text
|
| 74 |
+
stt_input = gr.Audio(label="Record Audio", type="filepath")
|
| 75 |
stt_button = gr.Button("Convert Speech to Text")
|
| 76 |
stt_output = gr.Textbox(label="Speech-to-Text Output")
|
| 77 |
stt_button.click(fn=speech_to_text, inputs=stt_input, outputs=stt_output)
|