mavihsrr commited on
Commit
e596b50
1 Parent(s): b67db24

added application files

Browse files
Files changed (2) hide show
  1. app.py +97 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ from PIL import Image
4
+ import google.generativeai as genai
5
+ from dotenv import load_dotenv
6
+ import os
7
+
8
+ load_dotenv()
9
+ api_key = os.getenv('api_key')
10
+ genai.configure(api_key=api_key)
11
+
12
+ def extract_frames(video_path, fps=30):
13
+ frames = []
14
+ cap = cv2.VideoCapture(video_path)
15
+
16
+ if not cap.isOpened():
17
+ raise ValueError("Error: Unable to open video file.")
18
+
19
+ original_fps = cap.get(cv2.CAP_PROP_FPS)
20
+ if original_fps == 0:
21
+ raise ValueError("Error: Unable to retrieve FPS from video file.")
22
+
23
+ frame_interval = int(original_fps // fps)
24
+ frame_count = 0
25
+ success, frame = cap.read()
26
+
27
+ while success:
28
+ if frame_count % frame_interval == 0:
29
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
30
+ pil_image = Image.fromarray(frame)
31
+ frames.append(pil_image)
32
+ frame_count += 1
33
+ success, frame = cap.read()
34
+
35
+ cap.release()
36
+ if len(frames) == 0:
37
+ raise ValueError("Error: No frames extracted from the video.")
38
+
39
+ return frames
40
+
41
+ def generate_prompt(button_list):
42
+ button_descriptions = ", ".join(button_list)
43
+ return (
44
+ f"Generate structured test cases for the following UI button(s): {button_descriptions}.\n\n"
45
+ "Functionality\n"
46
+ "- What the button is supposed to do.\n\n"
47
+ "Preconditions\n"
48
+ "- Any requirements before interaction.\n\n"
49
+ " Test Steps\n"
50
+ "- Concise steps for executing the test.\n\n"
51
+ "Expected Results\n"
52
+ "- What the expected outcome should be.\n\n"
53
+ "Automated Testing Tools\n"
54
+ "- Recommended tools for testing.\n\n"
55
+ "Format the output clearly for easy readability, using bullet points for key details."
56
+ )
57
+
58
+
59
+ def process_video(video_file, buttons_to_test):
60
+ try:
61
+ video_path = "uploaded_video.mp4"
62
+ with open(video_path, "wb") as f:
63
+ f.write(video_file)
64
+
65
+ # Extract frames
66
+ frames = extract_frames(video_path, fps=30)
67
+ button_list = [button.strip() for button in buttons_to_test.split(",")]
68
+ prompt = generate_prompt(button_list)
69
+ model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest")
70
+ response = model.generate_content([prompt])
71
+
72
+ output_text = response.text if hasattr(response, 'text') else "Error: Invalid response from the model."
73
+ output_text = output_text.replace("Functionality", "📋 Functionality")
74
+ output_text = output_text.replace("Preconditions", "🔍 Preconditions")
75
+ output_text = output_text.replace("Test Steps", "📝 Test Steps")
76
+ output_text = output_text.replace("Expected Results", "✅ Expected Results")
77
+ output_text = output_text.replace("Automated Testing Tools", "🛠️ Automated Testing Tools")
78
+
79
+ return output_text
80
+
81
+ except Exception as e:
82
+ return str(e)
83
+
84
+ iface = gr.Interface(
85
+ fn=process_video,
86
+ inputs=[
87
+ gr.File(label="Upload Video", type="binary"),
88
+ gr.Textbox(label="Buttons/Functions to Test (comma-separated)", placeholder="e.g., booking, cancel"),
89
+ ],
90
+ outputs="text",
91
+ title="UI Test Case Generator",
92
+ description="Upload a video and specify the buttons you want to test. The tool will generate structured test cases."
93
+ )
94
+
95
+ iface.launch(share=True)
96
+
97
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ python-dotenv
3
+ opencv-python
4
+ pillow
5
+ google-generativeai