themanas021 commited on
Commit
352bb9e
·
verified ·
1 Parent(s): 4e06004

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -0
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import base64
3
+ from PIL import Image
4
+ from groq import Groq
5
+ import os
6
+
7
+ client = Groq(api_key=os.environ.get('GROQ_API_KEY'))
8
+
9
+ def encode_images(image_paths):
10
+ base64_images = []
11
+ for image_path in image_paths:
12
+ with open(image_path, "rb") as image_file:
13
+ base64_image = base64.b64encode(image_file.read()).decode("utf-8")
14
+ base64_images.append(f"data:image/jpeg;base64,{base64_image}")
15
+ return base64_images
16
+
17
+ def resize_images(image_paths, target_size=(224, 224)):
18
+ resized_images = []
19
+ for image_path in image_paths:
20
+ img = Image.open(image_path)
21
+ img_resized = img.resize(target_size)
22
+ resized_images.append(img_resized)
23
+ return resized_images
24
+
25
+ def generate_testing_instructions(images, context):
26
+ resized_images = resize_images(images)
27
+
28
+ base64_images = encode_images(images)
29
+
30
+ completion = client.chat.completions.create(
31
+ model="llava-v1.5-7b-4096-preview",
32
+ messages=[
33
+ {
34
+ "role": "user",
35
+ "content": [
36
+ {"type": "image_url", "image_url": {"url": base64_image}},
37
+ {"type": "text", "text": '''
38
+ You're a helpful assistant that creates comprehensive testing instructions. Each test case should include the following details:
39
+
40
+ - **Description**: A brief explanation of the feature being tested.
41
+ - **Pre-conditions**: The required setup or state of the app before beginning the test.
42
+ - **Testing Steps**: A clear, step-by-step guide for performing the test, including any user interactions or actions.
43
+ - **Expected Result**: The outcome you should observe if the feature is functioning correctly.
44
+
45
+ Please demonstrate your approach using the following features of a mobile app:
46
+
47
+ 1. **Source, Destination, and Date Selection**: The user selects their departure location, destination, and the travel date.
48
+ 2. **Bus Selection**: Displays a list of available buses, allowing the user to choose a specific one.
49
+ 3. **Seat Selection**: Enables the user to select seats on the chosen bus.
50
+ 4. **Pick-up and Drop-off Point Selection**: Allows the user to specify the starting point and final stop for the trip.
51
+ 5. **Offers**: Showcases available promotions and discounts.
52
+ 6. **Filters**: Options to filter buses by time, price, or other preferences.
53
+ 7. **Bus Information**: Provides details about the selected bus, including amenities, photos, and reviews.
54
+
55
+ '''},
56
+ {"type": "text", "text": context}
57
+ ]
58
+ }
59
+ for base64_image in base64_images
60
+ ],
61
+ temperature=0,
62
+ max_tokens=1024,
63
+ top_p=1,
64
+ stream=False,
65
+ stop=None,
66
+ )
67
+ return completion.choices[0].message.content
68
+
69
+ with gr.Blocks() as demo:
70
+ gr.Markdown("## App Testing Instructions Generator")
71
+
72
+ with gr.Row():
73
+ context = gr.Textbox(label="Optional Context", placeholder="Add any specific instructions or questions...")
74
+
75
+ image_upload = gr.File(label="Upload Screenshots (PNG or JPG)", type="filepath", file_count="multiple")
76
+
77
+ output = gr.Textbox(label="Generated Testing Instructions", placeholder="The instructions will appear here...")
78
+
79
+ button = gr.Button("Describe Testing Instructions")
80
+
81
+ button.click(
82
+ generate_testing_instructions,
83
+ inputs=[image_upload, context],
84
+ outputs=output
85
+ )
86
+
87
+ demo.launch(debug=True)