Zeph27 commited on
Commit
d377414
Β·
1 Parent(s): 92a36c1

percentage progress

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -72,23 +72,30 @@ def transcribe_audio(audio_file):
72
  return transcription
73
 
74
  @spaces.GPU
75
- def analyze_video(prompt, video):
76
  start_time = time.time()
77
 
 
 
78
  if isinstance(video, str):
79
  video_path = video
80
  else:
81
  video_path = video.name
82
 
 
83
  encoded_video = encode_video(video_path)
84
 
 
85
  # Extract audio and transcribe
86
  audio_path = extract_audio(video_path)
 
 
87
  transcription = transcribe_audio(audio_path)
88
 
89
  # Clean up temporary audio file
90
  os.remove(audio_path)
91
 
 
92
  context = [
93
  {"role": "user", "content": [prompt] + encoded_video},
94
  {"role": "assistant", "content": f"Transcription of the video: {transcription}"}
@@ -105,12 +112,16 @@ def analyze_video(prompt, video):
105
  "max_slice_nums": 1 if len(encoded_video) > 16 else 2
106
  }
107
 
 
108
  response = model.chat(image=None, msgs=context, tokenizer=tokenizer, **params)
109
 
 
110
  end_time = time.time()
111
  processing_time = end_time - start_time
112
  analysis_result = f"Analysis Result:\n{response}\n\n"
113
  processing_time = f"Processing Time: {processing_time:.2f} seconds"
 
 
114
  return analysis_result, processing_time
115
 
116
  with gr.Blocks() as demo:
 
72
  return transcription
73
 
74
  @spaces.GPU
75
+ def analyze_video(prompt, video, progress=gr.Progress()):
76
  start_time = time.time()
77
 
78
+ progress(0, desc="Initializing")
79
+
80
  if isinstance(video, str):
81
  video_path = video
82
  else:
83
  video_path = video.name
84
 
85
+ progress(10, desc="Encoding video")
86
  encoded_video = encode_video(video_path)
87
 
88
+ progress(30, desc="Extracting audio")
89
  # Extract audio and transcribe
90
  audio_path = extract_audio(video_path)
91
+
92
+ progress(50, desc="Transcribing audio")
93
  transcription = transcribe_audio(audio_path)
94
 
95
  # Clean up temporary audio file
96
  os.remove(audio_path)
97
 
98
+ progress(70, desc="Preparing context")
99
  context = [
100
  {"role": "user", "content": [prompt] + encoded_video},
101
  {"role": "assistant", "content": f"Transcription of the video: {transcription}"}
 
112
  "max_slice_nums": 1 if len(encoded_video) > 16 else 2
113
  }
114
 
115
+ progress(80, desc="Generating response")
116
  response = model.chat(image=None, msgs=context, tokenizer=tokenizer, **params)
117
 
118
+ progress(90, desc="Finalizing")
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(100, desc="Complete")
125
  return analysis_result, processing_time
126
 
127
  with gr.Blocks() as demo: