Spaces:
Runtime error
Runtime error
KarthickAdopleAI
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,7 @@ class VideoAnalytics:
|
|
28 |
def __init__(self):
|
29 |
"""
|
30 |
Initialize the VideoAnalytics object.
|
|
|
31 |
Args:
|
32 |
hf_token (str): Hugging Face API token.
|
33 |
"""
|
@@ -39,7 +40,16 @@ class VideoAnalytics:
|
|
39 |
# Initialize transcribed text variable
|
40 |
self.transcribed_text = ""
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# Initialize english text variable
|
45 |
self.english_text = ""
|
@@ -55,8 +65,10 @@ class VideoAnalytics:
|
|
55 |
def transcribe_video(self, vid: str) -> str:
|
56 |
"""
|
57 |
Transcribe the audio of the video.
|
|
|
58 |
Args:
|
59 |
vid (str): Path to the video file.
|
|
|
60 |
Returns:
|
61 |
str: Transcribed text.
|
62 |
"""
|
@@ -68,18 +80,27 @@ class VideoAnalytics:
|
|
68 |
# Write audio to a temporary file
|
69 |
audio.write_audiofile("output_audio.mp3")
|
70 |
audio_file = open("output_audio.mp3", "rb")
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# Update the transcribed_text attribute with the transcription result
|
73 |
-
self.transcribed_text =
|
74 |
# Update the translation text into english_text
|
75 |
self.english_text = self.translation()
|
76 |
# Return the transcribed text
|
77 |
-
return
|
78 |
|
79 |
except Exception as e:
|
80 |
logging.error(f"Error transcribing video: {e}")
|
81 |
return ""
|
82 |
-
|
83 |
def generate_video_summary(self) -> str:
|
84 |
"""
|
85 |
Generate a summary of the transcribed video.
|
|
|
28 |
def __init__(self):
|
29 |
"""
|
30 |
Initialize the VideoAnalytics object.
|
31 |
+
|
32 |
Args:
|
33 |
hf_token (str): Hugging Face API token.
|
34 |
"""
|
|
|
40 |
# Initialize transcribed text variable
|
41 |
self.transcribed_text = ""
|
42 |
|
43 |
+
# API URL for accessing the Hugging Face model
|
44 |
+
self.API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
45 |
+
|
46 |
+
|
47 |
+
hf_token = os.getenv('HF_TOKEN')
|
48 |
+
# Placeholder for Hugging Face API token
|
49 |
+
self.hf_token = hf_token # Replace this with the actual Hugging Face API token
|
50 |
+
|
51 |
+
# Set headers for API requests with Hugging Face token
|
52 |
+
self.headers = {"Authorization": f"Bearer {self.hf_token}"}
|
53 |
|
54 |
# Initialize english text variable
|
55 |
self.english_text = ""
|
|
|
65 |
def transcribe_video(self, vid: str) -> str:
|
66 |
"""
|
67 |
Transcribe the audio of the video.
|
68 |
+
|
69 |
Args:
|
70 |
vid (str): Path to the video file.
|
71 |
+
|
72 |
Returns:
|
73 |
str: Transcribed text.
|
74 |
"""
|
|
|
80 |
# Write audio to a temporary file
|
81 |
audio.write_audiofile("output_audio.mp3")
|
82 |
audio_file = open("output_audio.mp3", "rb")
|
83 |
+
|
84 |
+
# Define a helper function to query the Hugging Face model
|
85 |
+
def query(data):
|
86 |
+
response = requests.post(self.API_URL, headers=self.headers, data=data)
|
87 |
+
return response.json()
|
88 |
+
|
89 |
+
# Send audio data to the Hugging Face model for transcription
|
90 |
+
output = query(audio_file)
|
91 |
+
|
92 |
+
print(output)
|
93 |
# Update the transcribed_text attribute with the transcription result
|
94 |
+
self.transcribed_text = output["text"]
|
95 |
# Update the translation text into english_text
|
96 |
self.english_text = self.translation()
|
97 |
# Return the transcribed text
|
98 |
+
return output["text"]
|
99 |
|
100 |
except Exception as e:
|
101 |
logging.error(f"Error transcribing video: {e}")
|
102 |
return ""
|
103 |
+
|
104 |
def generate_video_summary(self) -> str:
|
105 |
"""
|
106 |
Generate a summary of the transcribed video.
|