File size: 3,377 Bytes
3768bd5
 
 
d436c8a
 
3768bd5
5aea6d7
3768bd5
427a1fc
 
 
 
3768bd5
427a1fc
 
 
 
3768bd5
427a1fc
 
8a6fd43
427a1fc
 
 
 
 
 
 
 
 
 
 
 
 
 
3768bd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427a1fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3768bd5
 
8a6fd43
3768bd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import gradio as gr
import base64
from PIL import Image
from groq import Groq
import os

client = Groq(api_key=os.environ.get('GROQ_API_KEY'))

def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        base64_image = base64.b64encode(image_file.read()).decode("utf-8")
    return f"data:image/jpeg;base64,{base64_image}"

def resize_image(image_path, target_size=(224, 224)):
    img = Image.open(image_path)
    img_resized = img.resize(target_size) 
    return img_resized

def generate_testing_instructions(images, context):
    all_instructions = []
    
    for image in images:
        resized_image = resize_image(image)
        base64_image = encode_image(image)
        
        # Send only one image and the text block in a single message
        completion = client.chat.completions.create(
            model="llava-v1.5-7b-4096-preview",
            messages=[
                {
                    "role": "user",
                    "content": [
                        {"type": "image_url", "image_url": {"url": base64_image}},
                        {"type": "text", "text": '''
You're a helpful assistant that creates comprehensive testing instructions. Based on the screenshot of the app interface, you should tell:

- **Description**: A brief explanation of the feature being tested.
- **Pre-conditions**: The required setup or state of the app before beginning the test.
- **Testing Steps**: A clear, step-by-step guide for performing the test, including any user interactions or actions.
- **Expected Result**: The outcome you should observe if the feature is functioning correctly.

Please demonstrate your approach using the following features of a mobile app:

1. **Source, Destination, and Date Selection**: The user selects their departure location, destination, and the travel date.
2. **Bus Selection**: Displays a list of available buses, allowing the user to choose a specific one.
3. **Seat Selection**: Enables the user to select seats on the chosen bus.
4. **Pick-up and Drop-off Point Selection**: Allows the user to specify the starting point and final stop for the trip.
5. **Offers**: Showcases available promotions and discounts.
6. **Filters**: Options to filter buses by time, price, or other preferences.
7. **Bus Information**: Provides details about the selected bus, including amenities, photos, and reviews.

''' + context}
                    ]
                }
            ],
            temperature=0,
            max_tokens=1024,
            top_p=1,
            stream=False,
            stop=None,
        )
        
        all_instructions.append(completion.choices[0].message.content)

    return "\n\n".join(all_instructions)

with gr.Blocks() as demo:
    gr.Markdown("## 🚌 Red Bus App Testing Instructions Generator")

    with gr.Row():
        context = gr.Textbox(label="Optional Context", placeholder="Add any specific instructions or questions...")

    image_upload = gr.File(label="Upload Screenshots (PNG or JPG)", type="filepath", file_count="multiple")

    output = gr.Textbox(label="Generated Testing Instructions", placeholder="The instructions will appear here...")

    button = gr.Button("Describe Testing Instructions")

    button.click(
        generate_testing_instructions,
        inputs=[image_upload, context],
        outputs=output
    )

demo.launch(debug=True)