Spaces:
Running
Running
Upload 4 files
Browse files- README (2).md +13 -0
- app (15).py +113 -0
- gitattributes (2) +35 -0
- requirements (4).txt +3 -0
README (2).md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: TestingAssist
|
3 |
+
emoji: 💻
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.15.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
short_description: AI assistant for automating software test cases generation
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app (15).py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
import docx
|
5 |
+
from docx.shared import Pt
|
6 |
+
|
7 |
+
# OpenRouter API Key
|
8 |
+
OPENROUTER_API_KEY = "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"
|
9 |
+
OPENROUTER_MODEL = "sophosympatheia/rogue-rose-103b-v0.2:free"
|
10 |
+
|
11 |
+
# Initialize OpenAI client with OpenRouter base URL
|
12 |
+
print(f"Using API Key: {OPENROUTER_API_KEY}")
|
13 |
+
openai_client = openai.OpenAI(
|
14 |
+
api_key=OPENROUTER_API_KEY,
|
15 |
+
base_url="https://openrouter.ai/api/v1" # OpenRouter API endpoint
|
16 |
+
)
|
17 |
+
|
18 |
+
# Few-shot examples for test case generation
|
19 |
+
FEW_SHOT_EXAMPLES = """
|
20 |
+
Example 1:
|
21 |
+
Project: E-commerce Website
|
22 |
+
Requirement: Users should be able to add items to their cart.
|
23 |
+
Test Case:
|
24 |
+
1. Navigate to the product page.
|
25 |
+
2. Click the "Add to Cart" button.
|
26 |
+
3. Verify that the item appears in the cart.
|
27 |
+
|
28 |
+
Example 2:
|
29 |
+
Project: Banking App
|
30 |
+
Requirement: Users should be able to transfer funds between accounts.
|
31 |
+
Test Case:
|
32 |
+
1. Log in to the banking app.
|
33 |
+
2. Navigate to the "Transfer Funds" section.
|
34 |
+
3. Select the source and destination accounts.
|
35 |
+
4. Enter the amount and confirm the transfer.
|
36 |
+
5. Verify that the transaction is reflected in both accounts.
|
37 |
+
"""
|
38 |
+
|
39 |
+
# Function to generate test cases using OpenRouter API
|
40 |
+
def generate_test_cases(project_details):
|
41 |
+
print("Generating test cases...")
|
42 |
+
try:
|
43 |
+
response = openai_client.chat.completions.create(
|
44 |
+
model=OPENROUTER_MODEL,
|
45 |
+
messages=[
|
46 |
+
{
|
47 |
+
"role": "system",
|
48 |
+
"content": "You are a software testing expert. Your task is to generate test cases based on the provided project details. "
|
49 |
+
"Use the following examples as a guide:\n" + FEW_SHOT_EXAMPLES
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"role": "user",
|
53 |
+
"content": f"Project Details:\n{project_details}\n\nGenerate test cases for the above project."
|
54 |
+
}
|
55 |
+
]
|
56 |
+
)
|
57 |
+
print("Test cases generated.")
|
58 |
+
return response.choices[0].message.content
|
59 |
+
except Exception as e:
|
60 |
+
print(f"Error generating test cases: {e}")
|
61 |
+
return f"Error: {e}"
|
62 |
+
|
63 |
+
# Function to create a Word document
|
64 |
+
def create_word_document(content, filename="test_cases.docx"):
|
65 |
+
print("Creating Word document...")
|
66 |
+
doc = docx.Document()
|
67 |
+
doc.add_heading("Generated Test Cases", level=1)
|
68 |
+
|
69 |
+
# Add content to the document
|
70 |
+
for line in content.split("\n"):
|
71 |
+
if line.strip():
|
72 |
+
doc.add_paragraph(line)
|
73 |
+
|
74 |
+
# Save the document
|
75 |
+
doc.save(filename)
|
76 |
+
print(f"Word document saved as {filename}.")
|
77 |
+
return filename
|
78 |
+
|
79 |
+
# Gradio UI for software testing automation
|
80 |
+
def gradio_ui():
|
81 |
+
with gr.Blocks() as demo:
|
82 |
+
gr.Markdown("## Software Testing Automation Tool")
|
83 |
+
gr.Markdown("Upload project details or enter them as text to generate test cases and documentation.")
|
84 |
+
|
85 |
+
# Inputs
|
86 |
+
project_input = gr.Textbox(label="Enter Project Details", lines=5, placeholder="Describe the project requirements...")
|
87 |
+
file_upload = gr.File(label="Or Upload Project Document (TXT, PDF, DOCX)", file_types=[".txt", ".pdf", ".docx"])
|
88 |
+
|
89 |
+
# Outputs
|
90 |
+
output_text = gr.Textbox(label="Generated Test Cases", lines=10, interactive=False)
|
91 |
+
download_link = gr.File(label="Download Test Cases as Word Document")
|
92 |
+
|
93 |
+
# Buttons
|
94 |
+
generate_btn = gr.Button("Generate Test Cases")
|
95 |
+
|
96 |
+
# Event handling
|
97 |
+
generate_btn.click(
|
98 |
+
fn=lambda project_details: generate_test_cases(project_details),
|
99 |
+
inputs=[project_input],
|
100 |
+
outputs=[output_text]
|
101 |
+
)
|
102 |
+
generate_btn.click(
|
103 |
+
fn=lambda project_details: create_word_document(generate_test_cases(project_details)),
|
104 |
+
inputs=[project_input],
|
105 |
+
outputs=[download_link]
|
106 |
+
)
|
107 |
+
|
108 |
+
return demo
|
109 |
+
|
110 |
+
# Launch Gradio UI
|
111 |
+
demo = gradio_ui()
|
112 |
+
print("Launching Gradio UI...")
|
113 |
+
demo.launch()
|
gitattributes (2)
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
requirements (4).txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
openai
|
3 |
+
python-docx
|