Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +18 -0
- llm.py +71 -0
- test/EXAMPLE.png +0 -0
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
def response(USER_DATA, TOKEN) -> str:
|
6 |
+
return "ok"
|
7 |
+
|
8 |
+
|
9 |
+
with gr.Blocks() as llm:
|
10 |
+
slider = gr.Slider(10, 100, render=False)
|
11 |
+
chatbot = gr.ChatInterface(
|
12 |
+
fn=response,
|
13 |
+
multimodal=True,
|
14 |
+
title="MultiModel LLM for Testcase generation",
|
15 |
+
cache_examples=True,
|
16 |
+
)
|
17 |
+
|
18 |
+
llm.launch(debug=True)
|
llm.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
from PIL import Image
|
4 |
+
import gradio as gr
|
5 |
+
import time
|
6 |
+
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(
|
8 |
+
"MILVLG/imp-v1-3b",
|
9 |
+
torch_dtype=torch.float16,
|
10 |
+
device_map="auto",
|
11 |
+
trust_remote_code=True,
|
12 |
+
)
|
13 |
+
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained("MILVLG/imp-v1-3b", trust_remote_code=True)
|
15 |
+
|
16 |
+
|
17 |
+
def response(USER_DATA, TOKEN) -> str:
|
18 |
+
print(USER_DATA)
|
19 |
+
MESSAGE = USER_DATA["text"]
|
20 |
+
NUM_FILES = len(USER_DATA["files"])
|
21 |
+
FILES = USER_DATA["files"]
|
22 |
+
|
23 |
+
SYSTEM_PROMPT = f"""
|
24 |
+
A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed testcase related to image uploaded. You are tasked with generating detailed, step-by-step test cases for software functionality based on uploaded images. The user will provide one or more images of a software or website interface. For each image, generate a separate set of test cases following the format below:
|
25 |
+
|
26 |
+
'''Description: Provide a brief explanation of the functionality being tested, as inferred from the image.
|
27 |
+
Pre-conditions: Identify any setup requirements, dependencies, or conditions that must be met before testing can begin (e.g., user logged in, specific data pre-populated, etc.).
|
28 |
+
Testing Steps: Outline a clear, numbered sequence of actions that a user would take to test the functionality in the image.
|
29 |
+
Expected Result: Specify the expected outcome if the functionality is working as intended.'''
|
30 |
+
|
31 |
+
Ensure that:
|
32 |
+
Testcases should be related to validation of data, component interactions, navigation, etc.
|
33 |
+
Each testcase should have it's own Description, Pre-conidtions, Testing Steps, Expected Result.
|
34 |
+
|
35 |
+
USER: <image>\n{MESSAGE}
|
36 |
+
ASSISTANT:
|
37 |
+
"""
|
38 |
+
|
39 |
+
RES = generate_answer(FILES, SYSTEM_PROMPT)
|
40 |
+
|
41 |
+
response = f"{RES}."
|
42 |
+
return response
|
43 |
+
for i in range(len(response)):
|
44 |
+
time.sleep(0.025)
|
45 |
+
yield response[: i + 1]
|
46 |
+
|
47 |
+
|
48 |
+
def generate_answer(IMAGES: list, SYSTEM_PROMPT) -> str:
|
49 |
+
print(len(IMAGES))
|
50 |
+
|
51 |
+
INPUT_IDS = tokenizer(SYSTEM_PROMPT, return_tensors="pt").input_ids
|
52 |
+
|
53 |
+
RESULT = ""
|
54 |
+
for EACH_IMG in IMAGES:
|
55 |
+
image_path = EACH_IMG["path"]
|
56 |
+
image = Image.open(image_path)
|
57 |
+
image_tensor = model.image_preprocess(image)
|
58 |
+
|
59 |
+
output_ids = model.generate(
|
60 |
+
inputs=INPUT_IDS,
|
61 |
+
max_new_tokens=500,
|
62 |
+
images=image_tensor,
|
63 |
+
use_cache=False,
|
64 |
+
)[0]
|
65 |
+
CUR_RESULT = tokenizer.decode(
|
66 |
+
output_ids[INPUT_IDS.shape[1] :], skip_special_tokens=True
|
67 |
+
).strip()
|
68 |
+
|
69 |
+
RESULT = f"{RESULT} /n/n {CUR_RESULT}"
|
70 |
+
|
71 |
+
return RESULT
|
test/EXAMPLE.png
ADDED