Spaces:
Runtime error
Runtime error
update context
Browse files
app.py
CHANGED
|
@@ -82,23 +82,24 @@ def analyze_video(prompt, video, progress=gr.Progress()):
|
|
| 82 |
else:
|
| 83 |
video_path = video.name
|
| 84 |
|
| 85 |
-
progress(
|
| 86 |
encoded_video = encode_video(video_path)
|
| 87 |
|
| 88 |
-
progress(
|
| 89 |
# Extract audio and transcribe
|
| 90 |
audio_path = extract_audio(video_path)
|
| 91 |
|
| 92 |
-
progress(
|
| 93 |
transcription = transcribe_audio(audio_path)
|
| 94 |
|
| 95 |
# Clean up temporary audio file
|
| 96 |
os.remove(audio_path)
|
| 97 |
|
| 98 |
-
progress(
|
| 99 |
context = [
|
| 100 |
-
{"role": "user", "content":
|
| 101 |
-
{"role": "assistant", "content": f"Transcription of the video: {transcription}"}
|
|
|
|
| 102 |
]
|
| 103 |
params = {
|
| 104 |
'sampling': True,
|
|
@@ -112,16 +113,16 @@ def analyze_video(prompt, video, progress=gr.Progress()):
|
|
| 112 |
"max_slice_nums": 1 if len(encoded_video) > 16 else 2
|
| 113 |
}
|
| 114 |
|
| 115 |
-
progress(
|
| 116 |
response = model.chat(image=None, msgs=context, tokenizer=tokenizer, **params)
|
| 117 |
|
| 118 |
-
progress(
|
| 119 |
end_time = time.time()
|
| 120 |
processing_time = end_time - start_time
|
| 121 |
analysis_result = f"Analysis Result:\n{response}\n\n"
|
| 122 |
processing_time = f"Processing Time: {processing_time:.2f} seconds"
|
| 123 |
|
| 124 |
-
progress(
|
| 125 |
return analysis_result, processing_time
|
| 126 |
|
| 127 |
with gr.Blocks() as demo:
|
|
|
|
| 82 |
else:
|
| 83 |
video_path = video.name
|
| 84 |
|
| 85 |
+
progress(0.1, desc="Encoding video")
|
| 86 |
encoded_video = encode_video(video_path)
|
| 87 |
|
| 88 |
+
progress(0.3, desc="Extracting audio")
|
| 89 |
# Extract audio and transcribe
|
| 90 |
audio_path = extract_audio(video_path)
|
| 91 |
|
| 92 |
+
progress(0.5, desc="Transcribing audio")
|
| 93 |
transcription = transcribe_audio(audio_path)
|
| 94 |
|
| 95 |
# Clean up temporary audio file
|
| 96 |
os.remove(audio_path)
|
| 97 |
|
| 98 |
+
progress(0.7, desc="Preparing context")
|
| 99 |
context = [
|
| 100 |
+
{"role": "user", "content": encoded_video},
|
| 101 |
+
{"role": "assistant", "content": f"Transcription of the video: {transcription}"},
|
| 102 |
+
{"role": "user", "content": prompt}
|
| 103 |
]
|
| 104 |
params = {
|
| 105 |
'sampling': True,
|
|
|
|
| 113 |
"max_slice_nums": 1 if len(encoded_video) > 16 else 2
|
| 114 |
}
|
| 115 |
|
| 116 |
+
progress(0.8, desc="Generating response")
|
| 117 |
response = model.chat(image=None, msgs=context, tokenizer=tokenizer, **params)
|
| 118 |
|
| 119 |
+
progress(0.9, desc="Finalizing")
|
| 120 |
end_time = time.time()
|
| 121 |
processing_time = end_time - start_time
|
| 122 |
analysis_result = f"Analysis Result:\n{response}\n\n"
|
| 123 |
processing_time = f"Processing Time: {processing_time:.2f} seconds"
|
| 124 |
|
| 125 |
+
progress(1, desc="Complete")
|
| 126 |
return analysis_result, processing_time
|
| 127 |
|
| 128 |
with gr.Blocks() as demo:
|