Spaces:
Runtime error
Runtime error
Update app.py
Browse files1 unmodified line234567897 unmodified lines171819202122232425262728291 unmodified line31323334353637383940414 unmodified lines464748495051522 unmodified lines555657585960616263646566676869707172737475767778798081828384857 unmodified lines93949596971 unmodified lineimport cv2from PIL import Imageimport google.generativeai as genaifrom dotenv import load_dotenvimport osload_dotenv()api_key = os.getenv('api_key')7 unmodified linesraise ValueError("Error: Unable to open video file.")original_fps = cap.get(cv2.CAP_PROP_FPS)if original_fps == 0:raise ValueError("Error: Unable to retrieve FPS from video file.")frame_interval = int(original_fps // fps)frame_count = 0success, frame = cap.read()while success:if frame_count % frame_interval == 0:frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)1 unmodified lineframes.append(pil_image)frame_count += 1success, frame = cap.read()cap.release()if len(frames) == 0:raise ValueError("Error: No frames extracted from the video.")return framesdef generate_prompt(button_list):4 unmodified lines"- What the button is supposed to do.\n\n""Preconditions\n""- Any requirements before interaction.\n\n"" Test Steps\n""- Concise steps for executing the test.\n\n""Expected Results\n""- What the expected outcome should be.\n\n"2 unmodified lines"Format the output clearly for easy readability, using bullet points for key details.")def process_video(video_file, buttons_to_test):try:video_path = "uploaded_video.mp4"with open(video_path, "wb") as f:f.write(video_file)# Extract framesframes = extract_frames(video_path, fps=30)button_list = [button.strip() for button in buttons_to_test.split(",")]prompt = generate_prompt(button_list)model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest")response = model.generate_content([prompt])output_text = response.text if hasattr(response, 'text') else "Error: Invalid response from the model."output_text = output_text.replace("Functionality", "📋 Functionality")output_text = output_text.replace("Preconditions", "🔍 Preconditions")output_text = output_text.replace("Test Steps", "📝 Test Steps")output_text = output_text.replace("Expected Results", "✅ Expected Results")output_text = output_text.replace("Automated Testing Tools", "🛠️ Automated Testing Tools")return output_textexcept Exception as e:return str(e)iface = gr.Interface(fn=process_video,7 unmodified lines)iface.launch(share=True)1 unmodified line234567897 unmodified lines171819202122232425262728291 unmodified line3132333435363738394041424 unmodified lines474849505152532 unmodified lines56575859606162636465666768697071727374757677787980818283848586877 unmodified lines9596971 unmodified lineimport cv2from PIL import Imageimport google.generativeai as genaiimport osfrom dotenv import load_dotenvload_dotenv()api_key = os.getenv('api_key')7 unmodified linesraise ValueError("Error: Unable to open video file.")original_fps = cap.get(cv2.CAP_PROP_FPS)if original_fps <= 0:raise ValueError("Error: Unable to retrieve valid FPS from video file.")frame_interval = max(1, int(original_fps // fps))frame_count = 0success, frame = cap.read()while success:if frame_count % frame_interval == 0:frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)1 unmodified lineframes.append(pil_image)frame_count += 1success, frame = cap.read()cap.release()if len(frames) == 0:raise ValueError("Error: No frames extracted from the video.")return framesdef generate_prompt(button_list):4 unmodified lines"- What the button is supposed to do.\n\n""Preconditions\n""- Any requirements before interaction.\n\n""Test Steps\n""- Concise steps for executing the test.\n\n""Expected Results\n""- What the expected outcome should be.\n\n"2 unmodified lines"Format the output clearly for easy readability, using bullet points for key details.")def process_video(video_file, buttons_to_test):try:video_path = "uploaded_video.mp4"with open(video_path, "wb") as f:f.write(video_file)frames = extract_frames(video_path, fps=15)frames_to_pass = frames[::10] # use every 10th framebutton_list = [button.strip() for button in buttons_to_test.split(",")]prompt = generate_prompt(button_list)frame_prompts = [frame for frame in frames_to_pass]response = genai.GenerativeModel(model_name="gemini-1.5-pro-latest").generate_content([prompt] + frame_prompts)output_text = response.text if hasattr(response, 'text') else "Error: Invalid response from the model."output_text = output_text.replace("Functionality", "📋 Functionality")output_text = output_text.replace("Preconditions", "🔍 Preconditions")output_text = output_text.replace("Test Steps", "📝 Test Steps")output_text = output_text.replace("Expected Results", "✅ Expected Results")output_text = output_text.replace("Automated Testing Tools", "🛠️ Automated Testing Tools")return output_textexcept Exception as e:return f"Error occurred: {str(e)}"iface = gr.Interface(fn=process_video,7 unmodified lines)iface.launch(share=True)
app.py+22-22