themanas021 commited on
Commit
427a1fc
·
verified ·
1 Parent(s): 8a6fd43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -48
app.py CHANGED
@@ -6,38 +6,33 @@ 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
- # Combine all the base64 images into a single message
31
- image_blocks = [
32
- {"type": "image_url", "image_url": {"url": base64_image}}
33
- for base64_image in base64_images
34
- ]
35
 
36
- # Add the instructional text in the same message
37
- content_block = {
38
- "type": "text",
39
- "text": '''
40
- You're a helpful assistant that creates comprehensive testing instructions. Based on the screenshot of app interface you should tell:
 
 
 
 
 
 
 
 
 
41
 
42
  - **Description**: A brief explanation of the feature being tested.
43
  - **Pre-conditions**: The required setup or state of the app before beginning the test.
@@ -53,25 +48,21 @@ Please demonstrate your approach using the following features of a mobile app:
53
  5. **Offers**: Showcases available promotions and discounts.
54
  6. **Filters**: Options to filter buses by time, price, or other preferences.
55
  7. **Bus Information**: Provides details about the selected bus, including amenities, photos, and reviews.
56
- '''}
57
-
58
- # Single message combining all image URLs and text
59
- completion = client.chat.completions.create(
60
- model="llava-v1.5-7b-4096-preview",
61
- messages=[
62
- {
63
- "role": "user",
64
- "content": image_blocks + [content_block] # Add images and text as one user message
65
- }
66
- ],
67
- temperature=0,
68
- max_tokens=1024,
69
- top_p=1,
70
- stream=False,
71
- stop=None,
72
- )
73
-
74
- return completion.choices[0].message.content
75
 
76
  with gr.Blocks() as demo:
77
  gr.Markdown("## 🚌 Red Bus App Testing Instructions Generator")
 
6
 
7
  client = Groq(api_key=os.environ.get('GROQ_API_KEY'))
8
 
9
+ def encode_image(image_path):
10
+ with open(image_path, "rb") as image_file:
11
+ base64_image = base64.b64encode(image_file.read()).decode("utf-8")
12
+ return f"data:image/jpeg;base64,{base64_image}"
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ def resize_image(image_path, target_size=(224, 224)):
15
+ img = Image.open(image_path)
16
+ img_resized = img.resize(target_size)
17
+ return img_resized
18
 
19
+ def generate_testing_instructions(images, context):
20
+ all_instructions = []
 
 
 
21
 
22
+ for image in images:
23
+ resized_image = resize_image(image)
24
+ base64_image = encode_image(image)
25
+
26
+ # Send only one image and the text block in a single message
27
+ completion = client.chat.completions.create(
28
+ model="llava-v1.5-7b-4096-preview",
29
+ messages=[
30
+ {
31
+ "role": "user",
32
+ "content": [
33
+ {"type": "image_url", "image_url": {"url": base64_image}},
34
+ {"type": "text", "text": '''
35
+ You're a helpful assistant that creates comprehensive testing instructions. Based on the screenshot of the app interface, you should tell:
36
 
37
  - **Description**: A brief explanation of the feature being tested.
38
  - **Pre-conditions**: The required setup or state of the app before beginning the test.
 
48
  5. **Offers**: Showcases available promotions and discounts.
49
  6. **Filters**: Options to filter buses by time, price, or other preferences.
50
  7. **Bus Information**: Provides details about the selected bus, including amenities, photos, and reviews.
51
+
52
+ ''' + context}
53
+ ]
54
+ }
55
+ ],
56
+ temperature=0,
57
+ max_tokens=1024,
58
+ top_p=1,
59
+ stream=False,
60
+ stop=None,
61
+ )
62
+
63
+ all_instructions.append(completion.choices[0].message.content)
64
+
65
+ return "\n\n".join(all_instructions)
 
 
 
 
66
 
67
  with gr.Blocks() as demo:
68
  gr.Markdown("## 🚌 Red Bus App Testing Instructions Generator")