Spaces:
Sleeping
Sleeping
Dhrumit1314
commited on
Commit
•
20742ab
1
Parent(s):
e832bfd
Update app.py
Browse files
app.py
CHANGED
@@ -57,59 +57,53 @@ def hello2():
|
|
57 |
# Route for uploading video files
|
58 |
@app.route('/upload_video', methods=['POST'])
|
59 |
def upload_video():
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
# Return the transcript, summary, model name, video file ID, and audio file ID in the response
|
108 |
-
return jsonify({'message': 'successful', 'transcript': transcript, 'summary': summary, 'modelName': model_name,
|
109 |
-
'videoFileId': video_file_id, 'audioFileId': audio_file_id})
|
110 |
-
except Exception as e:
|
111 |
-
# If an error occurs during processing, return an error message
|
112 |
-
return jsonify({'error': str(e)})
|
113 |
|
114 |
# def upload_video():
|
115 |
# start_time = time.time()
|
|
|
57 |
# Route for uploading video files
|
58 |
@app.route('/upload_video', methods=['POST'])
|
59 |
def upload_video():
|
60 |
+
start_time = time.time()
|
61 |
+
if 'video' not in request.files:
|
62 |
+
return jsonify({'error': 'No video file found in the request'})
|
63 |
+
video = request.files['video']
|
64 |
+
if video.mimetype.split('/')[0] != 'video':
|
65 |
+
return jsonify({'error': 'The file uploaded is not a video'})
|
66 |
+
|
67 |
+
model_name = request.form.get('modelName')
|
68 |
+
print("MODEL:", model_name)
|
69 |
+
|
70 |
+
video_path = os.path.join(os.getcwd(), secure_filename(video.filename))
|
71 |
+
video.save(video_path)
|
72 |
+
|
73 |
+
# Initialize HfApi and HfFolder
|
74 |
+
api = HfApi()
|
75 |
+
folder = HfFolder()
|
76 |
+
|
77 |
+
# Get your Hugging Face API token
|
78 |
+
token = folder.get_token()
|
79 |
+
|
80 |
+
# Specify your namespace (username or organization name)
|
81 |
+
namespace = "Dhrumit1314/notivai-backend"
|
82 |
+
|
83 |
+
# Upload the video file
|
84 |
+
video_file_id = api.upload_file(
|
85 |
+
token=token,
|
86 |
+
path=video_path,
|
87 |
+
filename=video.filename,
|
88 |
+
namespace=namespace
|
89 |
+
)
|
90 |
+
|
91 |
+
transcript = transcribe_audio(video_path)
|
92 |
+
|
93 |
+
summary = ""
|
94 |
+
if model_name == 'T5':
|
95 |
+
summary = summarize_text_t5(transcript)
|
96 |
+
elif model_name == 'BART':
|
97 |
+
summary = summarize_text_bart(transcript)
|
98 |
+
else:
|
99 |
+
summary = summarizer(transcript)
|
100 |
+
|
101 |
+
end_time = time.time()
|
102 |
+
elapsed_time = end_time - start_time
|
103 |
+
print(f"Video saved successfully. Time taken: {elapsed_time} seconds")
|
104 |
+
|
105 |
+
return jsonify({'message': 'successful', 'transcript': transcript, 'summary': summary, 'modelName': model_name, 'videoFileId': video_file_id})
|
106 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
# def upload_video():
|
109 |
# start_time = time.time()
|