Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the model
|
5 |
+
model_name = "google/flan-t5-base" # Choose your desired model
|
6 |
+
generator = pipeline("text2text-generation", model=model_name)
|
7 |
+
|
8 |
+
# Function to generate test cases
|
9 |
+
def generate_test_cases(method, url, headers, payload):
|
10 |
+
prompt = f"""
|
11 |
+
Generate comprehensive API test cases:
|
12 |
+
Method: {method}
|
13 |
+
URL: {url}
|
14 |
+
Headers: {headers}
|
15 |
+
Payload: {payload}
|
16 |
+
|
17 |
+
Include:
|
18 |
+
- Happy path
|
19 |
+
- Negative test cases
|
20 |
+
- Performance scenarios
|
21 |
+
- Boundary conditions
|
22 |
+
"""
|
23 |
+
try:
|
24 |
+
response = generator(prompt, max_length=500)
|
25 |
+
return response[0]['generated_text']
|
26 |
+
except Exception as e:
|
27 |
+
return f"Error generating test cases: {str(e)}"
|
28 |
+
|
29 |
+
# Create the Gradio interface
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=generate_test_cases,
|
32 |
+
inputs=[
|
33 |
+
gr.Textbox(label="HTTP Method (GET, POST, etc.)"),
|
34 |
+
gr.Textbox(label="API URL"),
|
35 |
+
gr.Textbox(label="Headers (JSON format)"),
|
36 |
+
gr.Textbox(label="Payload (JSON format)"),
|
37 |
+
],
|
38 |
+
outputs="text",
|
39 |
+
title="API Test Case Generator",
|
40 |
+
description="Generate structured test cases for APIs using Hugging Face models."
|
41 |
+
)
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
iface.launch()
|