Dhrumit1314 commited on
Commit
424e067
1 Parent(s): d1cc910

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -36
app.py CHANGED
@@ -54,51 +54,51 @@ def hello():
54
  # return h
55
 
56
  # Route for uploading video files
57
- # @app.route('/upload_video', methods=['POST'])
58
- # def upload_video():
59
- # start_time = time.time()
60
- # if 'video' not in request.files:
61
- # return jsonify({'error': 'No video file found in the request'})
62
- # video = request.files['video']
63
- # if video.mimetype.split('/')[0] != 'video':
64
- # return jsonify({'error': 'The file uploaded is not a video'})
65
 
66
- # model_name = request.form.get('modelName')
67
- # print("MODEL:", model_name)
68
 
69
- # video_path = os.path.join(os.getcwd(), secure_filename(video.filename))
70
- # video.save(video_path)
71
 
72
- # # Initialize HfApi and HfFolder
73
- # api = HfApi()
74
- # folder = HfFolder()
75
 
76
- # token = folder.get_token()
77
- # namespace = "Dhrumit1314/videoUpload"
78
 
79
- # # Upload the video file
80
- # video_file_id = api.upload_file(
81
- # token=token,
82
- # path_or_fileobj=video_path,
83
- # repo_id=namespace,
84
- # path_in_repo=video.filename
85
- # )
86
 
87
- # transcript = transcribe_audio(video_path)
88
 
89
- # summary = ""
90
- # if model_name == 'T5':
91
- # summary = summarize_text_t5(transcript)
92
- # elif model_name == 'BART':
93
- # summary = summarize_text_bart(transcript)
94
- # else:
95
- # summary = summarizer(transcript)
96
 
97
- # end_time = time.time()
98
- # elapsed_time = end_time - start_time
99
- # print(f"Video saved successfully. Time taken: {elapsed_time} seconds")
100
 
101
- # return jsonify({'message': 'successful', 'transcript': transcript, 'summary': summary, 'modelName': model_name, 'videoFileId': video_file_id})
102
 
103
 
104
  # def upload_video():
 
54
  # return h
55
 
56
  # Route for uploading video files
57
+ @app.route('/upload_video', methods=['POST'])
58
+ def upload_video():
59
+ start_time = time.time()
60
+ if 'video' not in request.files:
61
+ return jsonify({'error': 'No video file found in the request'})
62
+ video = request.files['video']
63
+ if video.mimetype.split('/')[0] != 'video':
64
+ return jsonify({'error': 'The file uploaded is not a video'})
65
 
66
+ model_name = request.form.get('modelName')
67
+ print("MODEL:", model_name)
68
 
69
+ video_path = os.path.join(os.getcwd(), secure_filename(video.filename))
70
+ video.save(video_path)
71
 
72
+ # Initialize HfApi and HfFolder
73
+ api = HfApi()
74
+ folder = HfFolder()
75
 
76
+ token = folder.get_token()
77
+ namespace = "Dhrumit1314/videoUpload"
78
 
79
+ # Upload the video file
80
+ video_file_id = api.upload_file(
81
+ token=token,
82
+ path_or_fileobj=video_path,
83
+ repo_id=namespace,
84
+ path_in_repo=video.filename
85
+ )
86
 
87
+ transcript = transcribe_audio(video_path)
88
 
89
+ summary = ""
90
+ if model_name == 'T5':
91
+ summary = summarize_text_t5(transcript)
92
+ elif model_name == 'BART':
93
+ summary = summarize_text_bart(transcript)
94
+ else:
95
+ summary = summarizer(transcript)
96
 
97
+ end_time = time.time()
98
+ elapsed_time = end_time - start_time
99
+ print(f"Video saved successfully. Time taken: {elapsed_time} seconds")
100
 
101
+ return jsonify({'message': 'successful', 'transcript': transcript, 'summary': summary, 'modelName': model_name, 'videoFileId': video_file_id})
102
 
103
 
104
  # def upload_video():