Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,38 +6,33 @@ import os
|
|
| 6 |
|
| 7 |
client = Groq(api_key=os.environ.get('GROQ_API_KEY'))
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 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
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
{"type": "image_url", "image_url": {"url": base64_image}}
|
| 33 |
-
for base64_image in base64_images
|
| 34 |
-
]
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 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")
|