Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -131,7 +131,7 @@ def clean_ocr_text(text):
|
|
131 |
cleaned_text = '\n'.join([line.strip() for line in cleaned_text.splitlines() if len(line.strip()) > 2])
|
132 |
return cleaned_text
|
133 |
|
134 |
-
def get_information_from_video_using_OCR(video_path, interval=
|
135 |
"""Extract text from video frames using OCR and return the combined text content."""
|
136 |
cap = cv2.VideoCapture(video_path)
|
137 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
@@ -147,12 +147,17 @@ def get_information_from_video_using_OCR(video_path, interval=1):
|
|
147 |
break
|
148 |
|
149 |
if frame_count % frame_interval == 0:
|
150 |
-
|
|
|
|
|
|
|
151 |
text = pytesseract.image_to_string(preprocessed_frame, lang='eng', config='--psm 6 --oem 3')
|
152 |
cleaned_text = clean_ocr_text(text)
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
156 |
|
157 |
frame_count += 1
|
158 |
|
@@ -183,7 +188,7 @@ def process_video():
|
|
183 |
download_video(video_url, temp_video_path)
|
184 |
|
185 |
# Step 2: Get the information from the downloaded MP4 file synchronously
|
186 |
-
video_info = get_information_from_video_using_OCR(temp_video_path, interval=
|
187 |
|
188 |
if not video_info:
|
189 |
video_info = ""
|
@@ -233,8 +238,8 @@ def query_gemini_api(video_transcription, audio_transcription):
|
|
233 |
"3. Steps for Preparation: Provide a step-by-step breakdown of the recipe's preparation process, organized and numbered sequentially.\n"
|
234 |
"4. Cooking Techniques Used: Highlight the cooking techniques demonstrated in the video, such as searing, blitzing, wrapping, etc.\n"
|
235 |
"5. Equipment Needed: List all tools, appliances, or utensils mentioned, e.g., blender, hot pan, cling film, etc.\n"
|
236 |
-
"6. Nutritional Information (if inferred): Provide an approximate calorie count or nutritional breakdown based on the
|
237 |
-
"7. Serving size: In count of people or portion size.\n"
|
238 |
"8. Special Notes or Variations: Include any specific tips, variations, or alternatives mentioned.\n"
|
239 |
"9. Festive or Thematic Relevance: Note if the recipe has any special relevance to holidays, events, or seasons.\n"
|
240 |
"There are errors and missing parts in the video transcription part, if something is not able to interpret from the video information use the audio information\n"
|
|
|
131 |
cleaned_text = '\n'.join([line.strip() for line in cleaned_text.splitlines() if len(line.strip()) > 2])
|
132 |
return cleaned_text
|
133 |
|
134 |
+
def get_information_from_video_using_OCR(video_path, interval=2):
|
135 |
"""Extract text from video frames using OCR and return the combined text content."""
|
136 |
cap = cv2.VideoCapture(video_path)
|
137 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
|
|
147 |
break
|
148 |
|
149 |
if frame_count % frame_interval == 0:
|
150 |
+
timestamp = frame_count / fps # Calculate timestamp in seconds
|
151 |
+
preprocessed_frame = preprocess_frame(frame) # Preprocess the frame
|
152 |
+
|
153 |
+
# Perform OCR on the preprocessed frame
|
154 |
text = pytesseract.image_to_string(preprocessed_frame, lang='eng', config='--psm 6 --oem 3')
|
155 |
cleaned_text = clean_ocr_text(text)
|
156 |
+
|
157 |
+
if cleaned_text: # Only save non-empty results
|
158 |
+
with open(output_file, 'a', encoding='utf-8') as f:
|
159 |
+
f.write(cleaned_text + "\n\n")
|
160 |
+
print(f"Extracted text at {timestamp:.2f} seconds")
|
161 |
|
162 |
frame_count += 1
|
163 |
|
|
|
188 |
download_video(video_url, temp_video_path)
|
189 |
|
190 |
# Step 2: Get the information from the downloaded MP4 file synchronously
|
191 |
+
video_info = get_information_from_video_using_OCR(temp_video_path, interval=2)
|
192 |
|
193 |
if not video_info:
|
194 |
video_info = ""
|
|
|
238 |
"3. Steps for Preparation: Provide a step-by-step breakdown of the recipe's preparation process, organized and numbered sequentially.\n"
|
239 |
"4. Cooking Techniques Used: Highlight the cooking techniques demonstrated in the video, such as searing, blitzing, wrapping, etc.\n"
|
240 |
"5. Equipment Needed: List all tools, appliances, or utensils mentioned, e.g., blender, hot pan, cling film, etc.\n"
|
241 |
+
"6. Nutritional Information (if inferred): Provide an approximate calorie count or macro nutritional breakdown based on the recipe cooked and your understanding, the carbs, protein and other macros.\n"
|
242 |
+
"7. Serving size: In count of people or portion size according to you and the recipe cooked e.g., 2 people, 4 people, 2 bowls, 2 cups.\n"
|
243 |
"8. Special Notes or Variations: Include any specific tips, variations, or alternatives mentioned.\n"
|
244 |
"9. Festive or Thematic Relevance: Note if the recipe has any special relevance to holidays, events, or seasons.\n"
|
245 |
"There are errors and missing parts in the video transcription part, if something is not able to interpret from the video information use the audio information\n"
|