Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -87,13 +87,13 @@ class VideoClassifier:
|
|
| 87 |
start = time.time()
|
| 88 |
mp4_file = video_input
|
| 89 |
video_name = mp4_file.split("/")[-1]
|
| 90 |
-
wav_file = "
|
| 91 |
video_clip = VideoFileClip(mp4_file)
|
| 92 |
audioclip = video_clip.audio
|
| 93 |
wav_file = audioclip.write_audiofile(wav_file)
|
| 94 |
audioclip.close()
|
| 95 |
video_clip.close()
|
| 96 |
-
audiotrack = "
|
| 97 |
result = self.whisper_model.transcribe(audiotrack, fp16=False)
|
| 98 |
transcript = result["text"]
|
| 99 |
print("TRANSCRIPT",transcript)
|
|
@@ -102,7 +102,7 @@ class VideoClassifier:
|
|
| 102 |
time_taken_1 = round(end - start, 3)
|
| 103 |
# print("Time taken from video to transcript:", time_taken_1)
|
| 104 |
|
| 105 |
-
path = './
|
| 106 |
if not os.path.exists(path):
|
| 107 |
os.mkdir(path)
|
| 108 |
video = cv2.VideoCapture(video_input)
|
|
@@ -119,12 +119,12 @@ class VideoClassifier:
|
|
| 119 |
ret,frame = video.read()
|
| 120 |
if ret:
|
| 121 |
# if video is still left continue creating images
|
| 122 |
-
name = './
|
| 123 |
# writing the extracted images
|
| 124 |
# print ('Creating...' + name)
|
| 125 |
cv2.imwrite(name, frame)
|
| 126 |
image_paths = []
|
| 127 |
-
img_path = '
|
| 128 |
image_paths.append(img_path)
|
| 129 |
content = self.img_cap.predict_step(image_paths)
|
| 130 |
print("content",content)
|
|
@@ -144,7 +144,7 @@ class VideoClassifier:
|
|
| 144 |
video.release()
|
| 145 |
cv2.destroyAllWindows()
|
| 146 |
|
| 147 |
-
main_categories = Path("
|
| 148 |
main_categories_list = ['Automotive', 'Books and Literature', 'Business and Finance', 'Careers', 'Education','Family and Relationships',
|
| 149 |
'Fine Art', 'Food & Drink', 'Healthy Living', 'Hobbies & Interests', 'Home & Garden','Medical Health', 'Movies', 'Music and Audio',
|
| 150 |
'News and Politics', 'Personal Finance', 'Pets', 'Pop Culture','Real Estate', 'Religion & Spirituality', 'Science', 'Shopping', 'Sports',
|
|
@@ -199,18 +199,18 @@ class VideoClassifier:
|
|
| 199 |
print("POST PROCESSED MAIN CLASS : ",main_class)
|
| 200 |
tier_1_index_no = main_categories_list.index(main_class) + 1
|
| 201 |
|
| 202 |
-
with open('
|
| 203 |
data = json.load(f)
|
| 204 |
sub_categories_list = data[main_class]
|
| 205 |
print("SUB CATEGORIES LIST",sub_categories_list)
|
| 206 |
-
with open("
|
| 207 |
no = 1
|
| 208 |
|
| 209 |
# print(data[main_class])
|
| 210 |
for i in data[main_class]:
|
| 211 |
f.write(str(no)+')'+str(i) + '\n')
|
| 212 |
no = no+1
|
| 213 |
-
sub_categories = Path("
|
| 214 |
|
| 215 |
template2 = '''Given below are the sub classes of {main_class}.
|
| 216 |
|
|
@@ -256,8 +256,8 @@ class VideoClassifier:
|
|
| 256 |
print("ANSWER:",sub_class)
|
| 257 |
final_answer = (f"Tier 1 category : IAB{tier_1_index_no} : {main_class}\nTier 2 category : IAB{tier_1_index_no}-{tier_2_index_no} : {sub_class}")
|
| 258 |
|
| 259 |
-
first_video = os.path.join(os.path.dirname(__file__), "
|
| 260 |
-
second_video = os.path.join(os.path.dirname(__file__), "
|
| 261 |
|
| 262 |
# return final_answer, first_video, second_video
|
| 263 |
return final_answer
|
|
@@ -280,10 +280,10 @@ class VideoClassifier:
|
|
| 280 |
"""
|
| 281 |
demo = gr.Interface(fn=self.classify_video, inputs="playablevideo",allow_flagging='never', examples=[
|
| 282 |
os.path.join(os.path.dirname(__file__),
|
| 283 |
-
"
|
| 284 |
-
os.path.join(os.path.dirname(__file__), "
|
| 285 |
-
os.path.join(os.path.dirname(__file__), "
|
| 286 |
-
os.path.join(os.path.dirname(__file__), "
|
| 287 |
cache_examples=False,
|
| 288 |
# outputs=["text", gr.Video(height=80, width=120), gr.Video(height=80, width=120)],
|
| 289 |
outputs=["text"],
|
|
|
|
| 87 |
start = time.time()
|
| 88 |
mp4_file = video_input
|
| 89 |
video_name = mp4_file.split("/")[-1]
|
| 90 |
+
wav_file = "audiotrack.wav"
|
| 91 |
video_clip = VideoFileClip(mp4_file)
|
| 92 |
audioclip = video_clip.audio
|
| 93 |
wav_file = audioclip.write_audiofile(wav_file)
|
| 94 |
audioclip.close()
|
| 95 |
video_clip.close()
|
| 96 |
+
audiotrack = "audiotrack.wav"
|
| 97 |
result = self.whisper_model.transcribe(audiotrack, fp16=False)
|
| 98 |
transcript = result["text"]
|
| 99 |
print("TRANSCRIPT",transcript)
|
|
|
|
| 102 |
time_taken_1 = round(end - start, 3)
|
| 103 |
# print("Time taken from video to transcript:", time_taken_1)
|
| 104 |
|
| 105 |
+
path = './frames'
|
| 106 |
if not os.path.exists(path):
|
| 107 |
os.mkdir(path)
|
| 108 |
video = cv2.VideoCapture(video_input)
|
|
|
|
| 119 |
ret,frame = video.read()
|
| 120 |
if ret:
|
| 121 |
# if video is still left continue creating images
|
| 122 |
+
name = './frames/frame' + str(currentframe) + '.jpg'
|
| 123 |
# writing the extracted images
|
| 124 |
# print ('Creating...' + name)
|
| 125 |
cv2.imwrite(name, frame)
|
| 126 |
image_paths = []
|
| 127 |
+
img_path = '/frames/frame' + str(currentframe) + '.jpg'
|
| 128 |
image_paths.append(img_path)
|
| 129 |
content = self.img_cap.predict_step(image_paths)
|
| 130 |
print("content",content)
|
|
|
|
| 144 |
video.release()
|
| 145 |
cv2.destroyAllWindows()
|
| 146 |
|
| 147 |
+
main_categories = Path("main_classes.txt").read_text()
|
| 148 |
main_categories_list = ['Automotive', 'Books and Literature', 'Business and Finance', 'Careers', 'Education','Family and Relationships',
|
| 149 |
'Fine Art', 'Food & Drink', 'Healthy Living', 'Hobbies & Interests', 'Home & Garden','Medical Health', 'Movies', 'Music and Audio',
|
| 150 |
'News and Politics', 'Personal Finance', 'Pets', 'Pop Culture','Real Estate', 'Religion & Spirituality', 'Science', 'Shopping', 'Sports',
|
|
|
|
| 199 |
print("POST PROCESSED MAIN CLASS : ",main_class)
|
| 200 |
tier_1_index_no = main_categories_list.index(main_class) + 1
|
| 201 |
|
| 202 |
+
with open('categories_json.txt') as f:
|
| 203 |
data = json.load(f)
|
| 204 |
sub_categories_list = data[main_class]
|
| 205 |
print("SUB CATEGORIES LIST",sub_categories_list)
|
| 206 |
+
with open("sub_categories.txt", "w") as f:
|
| 207 |
no = 1
|
| 208 |
|
| 209 |
# print(data[main_class])
|
| 210 |
for i in data[main_class]:
|
| 211 |
f.write(str(no)+')'+str(i) + '\n')
|
| 212 |
no = no+1
|
| 213 |
+
sub_categories = Path("sub_categories.txt").read_text()
|
| 214 |
|
| 215 |
template2 = '''Given below are the sub classes of {main_class}.
|
| 216 |
|
|
|
|
| 256 |
print("ANSWER:",sub_class)
|
| 257 |
final_answer = (f"Tier 1 category : IAB{tier_1_index_no} : {main_class}\nTier 2 category : IAB{tier_1_index_no}-{tier_2_index_no} : {sub_class}")
|
| 258 |
|
| 259 |
+
first_video = os.path.join(os.path.dirname(__file__), "American_football_heads_to_India_clip.mp4")
|
| 260 |
+
second_video = os.path.join(os.path.dirname(__file__), "PersonalFinance_clip.mp4")
|
| 261 |
|
| 262 |
# return final_answer, first_video, second_video
|
| 263 |
return final_answer
|
|
|
|
| 280 |
"""
|
| 281 |
demo = gr.Interface(fn=self.classify_video, inputs="playablevideo",allow_flagging='never', examples=[
|
| 282 |
os.path.join(os.path.dirname(__file__),
|
| 283 |
+
"American_football_heads_to_India_clip.mp4"),os.path.join(os.path.dirname(__file__), "PersonalFinance_clip.mp4"),
|
| 284 |
+
os.path.join(os.path.dirname(__file__), "Motorcycle_clip.mp4"),
|
| 285 |
+
os.path.join(os.path.dirname(__file__), "Spirituality_1_clip.mp4"),
|
| 286 |
+
os.path.join(os.path.dirname(__file__), "Science_clip.mp4")],
|
| 287 |
cache_examples=False,
|
| 288 |
# outputs=["text", gr.Video(height=80, width=120), gr.Video(height=80, width=120)],
|
| 289 |
outputs=["text"],
|