Spaces:
Sleeping
Sleeping
Commit
·
b33d37d
1
Parent(s):
4682e8b
new update
Browse files
app.py
CHANGED
|
@@ -5,35 +5,31 @@ from huggingface_hub import hf_hub_download
|
|
| 5 |
from nltk.corpus import stopwords
|
| 6 |
from nltk.stem import WordNetLemmatizer
|
| 7 |
import gensim
|
| 8 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Load stop words and lemmatizer
|
| 11 |
stop_words = set(stopwords.words('english'))
|
| 12 |
lemmatizer = WordNetLemmatizer()
|
| 13 |
|
| 14 |
-
# Function to preprocess input text
|
| 15 |
def preprocess_text(input_text, word2vec_model):
|
| 16 |
-
# Convert to lowercase
|
| 17 |
input_text = input_text.lower()
|
| 18 |
-
|
| 19 |
-
# Tokenize words
|
| 20 |
tokens = input_text.split()
|
| 21 |
-
|
| 22 |
-
# Remove stop words
|
| 23 |
tokens = [token for token in tokens if token not in stop_words]
|
| 24 |
-
|
| 25 |
-
# Lemmatize tokens
|
| 26 |
tokens = [lemmatizer.lemmatize(token, pos='v') for token in tokens]
|
| 27 |
-
|
| 28 |
-
# Generate Word2Vec embeddings for tokens
|
| 29 |
embeddings = []
|
|
|
|
| 30 |
for token in tokens:
|
| 31 |
if token in word2vec_model.wv:
|
| 32 |
embeddings.append(word2vec_model.wv[token])
|
| 33 |
else:
|
| 34 |
-
embeddings.append(np.zeros(word2vec_model.vector_size))
|
| 35 |
|
| 36 |
-
# Pad or truncate embeddings to match time_steps (e.g., 100)
|
| 37 |
max_timesteps = 100
|
| 38 |
if len(embeddings) > max_timesteps:
|
| 39 |
embeddings = embeddings[:max_timesteps]
|
|
@@ -41,26 +37,22 @@ def preprocess_text(input_text, word2vec_model):
|
|
| 41 |
padding = [np.zeros(word2vec_model.vector_size)] * (max_timesteps - len(embeddings))
|
| 42 |
embeddings.extend(padding)
|
| 43 |
|
| 44 |
-
# Convert to NumPy array and reshape
|
| 45 |
input_features = np.array(embeddings).reshape((1, max_timesteps, word2vec_model.vector_size))
|
| 46 |
return input_features
|
| 47 |
|
| 48 |
# Load Word2Vec model
|
| 49 |
def load_word2vec_model():
|
| 50 |
-
word2vec_path = '/Users/preethamreddygollapalli/Downloads/word2vec_model.bin'
|
|
|
|
|
|
|
| 51 |
return gensim.models.Word2Vec.load(word2vec_path)
|
| 52 |
|
| 53 |
-
# Load LSTM model
|
| 54 |
def load_model_test_steps():
|
| 55 |
repo_id = 'Preethamreddy799/NLP_MODEL'
|
| 56 |
-
filename = 'model_test_steps.h5'
|
| 57 |
-
|
| 58 |
-
# Download the model from Hugging Face
|
| 59 |
cached_model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 60 |
-
|
| 61 |
-
# Load the model from the cached path
|
| 62 |
model = load_model(cached_model_path)
|
| 63 |
-
|
| 64 |
print(f"Model loaded successfully from {cached_model_path}")
|
| 65 |
return model
|
| 66 |
|
|
@@ -72,23 +64,19 @@ lstm_model = load_model_test_steps()
|
|
| 72 |
st.title("Test Case Steps Generator")
|
| 73 |
st.write("This app generates test steps based on Test Case Acceptance Criteria.")
|
| 74 |
|
| 75 |
-
# Input section
|
| 76 |
acceptance_criteria = st.text_area("Enter Test Case Acceptance Criteria")
|
| 77 |
|
| 78 |
-
# Generate Test Steps
|
| 79 |
if st.button("Generate Test Steps"):
|
| 80 |
if acceptance_criteria:
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
-
|
| 86 |
predicted_steps = lstm_model.predict(input_features)
|
| 87 |
-
|
| 88 |
-
# Display the results
|
| 89 |
st.subheader("Generated Test Steps")
|
| 90 |
st.write(predicted_steps)
|
| 91 |
-
|
| 92 |
-
st.error("
|
| 93 |
else:
|
| 94 |
-
st.warning("Please fill Acceptance Criteria.")
|
|
|
|
| 5 |
from nltk.corpus import stopwords
|
| 6 |
from nltk.stem import WordNetLemmatizer
|
| 7 |
import gensim
|
| 8 |
+
import nltk
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
# Download necessary NLTK resources
|
| 12 |
+
nltk.download('stopwords')
|
| 13 |
+
nltk.download('wordnet')
|
| 14 |
|
| 15 |
# Load stop words and lemmatizer
|
| 16 |
stop_words = set(stopwords.words('english'))
|
| 17 |
lemmatizer = WordNetLemmatizer()
|
| 18 |
|
| 19 |
+
# Function to preprocess input text
|
| 20 |
def preprocess_text(input_text, word2vec_model):
|
|
|
|
| 21 |
input_text = input_text.lower()
|
|
|
|
|
|
|
| 22 |
tokens = input_text.split()
|
|
|
|
|
|
|
| 23 |
tokens = [token for token in tokens if token not in stop_words]
|
|
|
|
|
|
|
| 24 |
tokens = [lemmatizer.lemmatize(token, pos='v') for token in tokens]
|
|
|
|
|
|
|
| 25 |
embeddings = []
|
| 26 |
+
|
| 27 |
for token in tokens:
|
| 28 |
if token in word2vec_model.wv:
|
| 29 |
embeddings.append(word2vec_model.wv[token])
|
| 30 |
else:
|
| 31 |
+
embeddings.append(np.zeros(word2vec_model.vector_size))
|
| 32 |
|
|
|
|
| 33 |
max_timesteps = 100
|
| 34 |
if len(embeddings) > max_timesteps:
|
| 35 |
embeddings = embeddings[:max_timesteps]
|
|
|
|
| 37 |
padding = [np.zeros(word2vec_model.vector_size)] * (max_timesteps - len(embeddings))
|
| 38 |
embeddings.extend(padding)
|
| 39 |
|
|
|
|
| 40 |
input_features = np.array(embeddings).reshape((1, max_timesteps, word2vec_model.vector_size))
|
| 41 |
return input_features
|
| 42 |
|
| 43 |
# Load Word2Vec model
|
| 44 |
def load_word2vec_model():
|
| 45 |
+
word2vec_path = '/Users/preethamreddygollapalli/Downloads/word2vec_model.bin'
|
| 46 |
+
if not os.path.exists(word2vec_path):
|
| 47 |
+
raise FileNotFoundError(f"Word2Vec model file not found at {word2vec_path}")
|
| 48 |
return gensim.models.Word2Vec.load(word2vec_path)
|
| 49 |
|
| 50 |
+
# Load LSTM model
|
| 51 |
def load_model_test_steps():
|
| 52 |
repo_id = 'Preethamreddy799/NLP_MODEL'
|
| 53 |
+
filename = 'model_test_steps.h5'
|
|
|
|
|
|
|
| 54 |
cached_model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
|
|
|
|
|
|
| 55 |
model = load_model(cached_model_path)
|
|
|
|
| 56 |
print(f"Model loaded successfully from {cached_model_path}")
|
| 57 |
return model
|
| 58 |
|
|
|
|
| 64 |
st.title("Test Case Steps Generator")
|
| 65 |
st.write("This app generates test steps based on Test Case Acceptance Criteria.")
|
| 66 |
|
|
|
|
| 67 |
acceptance_criteria = st.text_area("Enter Test Case Acceptance Criteria")
|
| 68 |
|
|
|
|
| 69 |
if st.button("Generate Test Steps"):
|
| 70 |
if acceptance_criteria:
|
| 71 |
+
input_features = preprocess_text(acceptance_criteria, word2vec_model)
|
| 72 |
+
print("Input Features Shape:", input_features.shape)
|
| 73 |
+
print("Expected Model Input Shape:", lstm_model.input_shape)
|
| 74 |
|
| 75 |
+
try:
|
| 76 |
predicted_steps = lstm_model.predict(input_features)
|
|
|
|
|
|
|
| 77 |
st.subheader("Generated Test Steps")
|
| 78 |
st.write(predicted_steps)
|
| 79 |
+
except Exception as e:
|
| 80 |
+
st.error(f"Error generating predictions: {e}")
|
| 81 |
else:
|
| 82 |
+
st.warning("Please fill in Acceptance Criteria.")
|