HarshitaSuri commited on
Commit
a547e0e
Β·
verified Β·
1 Parent(s): fd90c92

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import requests
4
+ from jsonschema import validate, ValidationError
5
+
6
+ def run_tests(file):
7
+ results = []
8
+ with open(file.name, "r") as f:
9
+ test_cases = json.load(f)
10
+
11
+ for case in test_cases:
12
+ try:
13
+ response = requests.request(
14
+ method=case["method"],
15
+ url=f"http://your-api-domain.com{case['endpoint']}", # Replace with your deployed .NET API URL
16
+ json=case["payload"]
17
+ )
18
+ validate(instance=response.json(), schema=case["expected_schema"])
19
+ results.append(f"{case['endpoint']} βœ… Passed")
20
+ except ValidationError as e:
21
+ results.append(f"{case['endpoint']} ❌ Failed: {e.message}")
22
+ except Exception as e:
23
+ results.append(f"{case['endpoint']} ❌ Error: {str(e)}")
24
+
25
+ return "\n".join(results)
26
+
27
+ demo = gr.Interface(
28
+ fn=run_tests,
29
+ inputs=gr.File(label="Upload Test Case JSON"),
30
+ outputs="text",
31
+ title="AI-Powered Test Runner",
32
+ description="Upload a JSON file with test cases to validate your .NET/React API."
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ demo.launch()