Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,35 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
model
|
| 5 |
-
|
| 6 |
-
model=
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def generate_test_cases(requirement):
|
| 10 |
# Creating a prompt for generating test cases
|
| 11 |
prompt = f"Generate test cases for the following software requirement in JSON format: '{requirement}'. Only provide the JSON array of test cases."
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Example usage
|
| 16 |
if __name__ == "__main__":
|
| 17 |
requirement = "User login functionality"
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
+
# Initialize the model pipeline
|
| 4 |
+
print("Initializing model pipeline...")
|
| 5 |
+
try:
|
| 6 |
+
model = pipeline(
|
| 7 |
+
"text-generation",
|
| 8 |
+
model="EleutherAI/gpt-neo-1.3B", # Use GPT-Neo 1.3B as an example
|
| 9 |
+
torch_dtype=torch.float32 # Use float32 to avoid mixed precision issues
|
| 10 |
+
)
|
| 11 |
+
print("Model pipeline initialized successfully.")
|
| 12 |
+
except Exception as e:
|
| 13 |
+
print(f"Error initializing model: {e}")
|
| 14 |
+
raise
|
| 15 |
|
| 16 |
def generate_test_cases(requirement):
|
| 17 |
# Creating a prompt for generating test cases
|
| 18 |
prompt = f"Generate test cases for the following software requirement in JSON format: '{requirement}'. Only provide the JSON array of test cases."
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
print("Generating test cases...")
|
| 22 |
+
result = model(prompt, max_length=300, num_return_sequences=1)[0]["generated_text"]
|
| 23 |
+
print("Test cases generated successfully.")
|
| 24 |
+
return result.strip()
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(f"Error during generation: {e}")
|
| 27 |
+
raise
|
| 28 |
|
| 29 |
# Example usage
|
| 30 |
if __name__ == "__main__":
|
| 31 |
requirement = "User login functionality"
|
| 32 |
+
try:
|
| 33 |
+
print(generate_test_cases(requirement))
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Error in application: {e}")
|