Spaces:
No application file
No application file
Update streamlit_app.py
Browse files- streamlit_app.py +16 -15
streamlit_app.py
CHANGED
|
@@ -4,15 +4,22 @@ import os
|
|
| 4 |
import docx2txt
|
| 5 |
import PyPDF2
|
| 6 |
|
| 7 |
-
#
|
|
|
|
|
|
|
| 8 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
client = Groq(api_key=GROQ_API_KEY)
|
| 10 |
|
| 11 |
# ------------------------------
|
| 12 |
# Streamlit page config and theme
|
| 13 |
# ------------------------------
|
| 14 |
st.set_page_config(page_title="🧪 TestCase Studio", layout="wide")
|
| 15 |
-
st.title("
|
| 16 |
|
| 17 |
# Custom CSS for clean theme
|
| 18 |
st.markdown(
|
|
@@ -23,13 +30,12 @@ st.markdown(
|
|
| 23 |
.stTextArea>div>div>textarea {font-size: 14px;}
|
| 24 |
.stFileUploader>div>div>label {font-weight: bold;}
|
| 25 |
.stExpanderHeader {font-weight: bold; font-size: 16px; color: #00796b;}
|
| 26 |
-
.testcase-box {background-color: #ffffff; padding: 10px; margin-bottom: 5px; border-radius: 8px; box-shadow: 0 0 5px rgba(0,0,0,0.1);}
|
| 27 |
</style>
|
| 28 |
""",
|
| 29 |
unsafe_allow_html=True
|
| 30 |
)
|
| 31 |
|
| 32 |
-
st.write("Choose
|
| 33 |
|
| 34 |
# ------------------------------
|
| 35 |
# Input method selection
|
|
@@ -44,7 +50,7 @@ if input_method == "Upload File":
|
|
| 44 |
else:
|
| 45 |
manual_text = st.text_area("Paste requirement text here", height=200)
|
| 46 |
|
| 47 |
-
num_testcases = st.number_input("Approximate number of test cases to generate", min_value=1, max_value=50, value=
|
| 48 |
|
| 49 |
generate_btn = st.button("Generate Test Cases")
|
| 50 |
|
|
@@ -68,7 +74,7 @@ def read_file(file):
|
|
| 68 |
# ------------------------------
|
| 69 |
# Call Groq API to generate test cases
|
| 70 |
# ------------------------------
|
| 71 |
-
def call_groq_generate_testcases(text, num_testcases=
|
| 72 |
prompt = f"""
|
| 73 |
You are a QA expert. For the following requirement, generate approximately {num_testcases} detailed test cases in the following clean format:
|
| 74 |
|
|
@@ -83,14 +89,14 @@ Steps:
|
|
| 83 |
Expected Result: <Expected Result>
|
| 84 |
====================================================
|
| 85 |
|
| 86 |
-
ONLY return the test cases in this clean format with
|
| 87 |
Requirement:
|
| 88 |
\"\"\"{text}\"\"\"
|
| 89 |
"""
|
| 90 |
response = client.chat.completions.create(
|
| 91 |
model="llama-3.1-8b-instant",
|
| 92 |
messages=[{"role":"user", "content": prompt}],
|
| 93 |
-
max_tokens=
|
| 94 |
)
|
| 95 |
return response.choices[0].message.content
|
| 96 |
|
|
@@ -98,7 +104,6 @@ Requirement:
|
|
| 98 |
# Generate test cases
|
| 99 |
# ------------------------------
|
| 100 |
if generate_btn:
|
| 101 |
-
# Get requirement text
|
| 102 |
if input_method == "Upload File":
|
| 103 |
if uploaded_file is not None:
|
| 104 |
try:
|
|
@@ -123,14 +128,10 @@ if generate_btn:
|
|
| 123 |
st.error(f"Error generating test cases: {e}")
|
| 124 |
st.stop()
|
| 125 |
|
| 126 |
-
# Display test cases as card style
|
| 127 |
st.subheader("🔸 Generated Test Cases")
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
if block:
|
| 131 |
-
st.markdown(f'<div class="testcase-box"><pre>{block}</pre></div>', unsafe_allow_html=True)
|
| 132 |
|
| 133 |
-
# Copy + Download
|
| 134 |
st.download_button(
|
| 135 |
"Download Test Cases as TXT",
|
| 136 |
testcases_output,
|
|
|
|
| 4 |
import docx2txt
|
| 5 |
import PyPDF2
|
| 6 |
|
| 7 |
+
# ------------------------------
|
| 8 |
+
# Load API key from Hugging Face Secret
|
| 9 |
+
# ------------------------------
|
| 10 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
+
|
| 12 |
+
if not GROQ_API_KEY:
|
| 13 |
+
st.error("⚠️ GROQ_API_KEY secret not found. Please add it in Hugging Face Space Settings → Secrets.")
|
| 14 |
+
st.stop()
|
| 15 |
+
|
| 16 |
client = Groq(api_key=GROQ_API_KEY)
|
| 17 |
|
| 18 |
# ------------------------------
|
| 19 |
# Streamlit page config and theme
|
| 20 |
# ------------------------------
|
| 21 |
st.set_page_config(page_title="🧪 TestCase Studio", layout="wide")
|
| 22 |
+
st.title("TestCase Studio")
|
| 23 |
|
| 24 |
# Custom CSS for clean theme
|
| 25 |
st.markdown(
|
|
|
|
| 30 |
.stTextArea>div>div>textarea {font-size: 14px;}
|
| 31 |
.stFileUploader>div>div>label {font-weight: bold;}
|
| 32 |
.stExpanderHeader {font-weight: bold; font-size: 16px; color: #00796b;}
|
|
|
|
| 33 |
</style>
|
| 34 |
""",
|
| 35 |
unsafe_allow_html=True
|
| 36 |
)
|
| 37 |
|
| 38 |
+
st.write("Choose one input method to provide requirements:")
|
| 39 |
|
| 40 |
# ------------------------------
|
| 41 |
# Input method selection
|
|
|
|
| 50 |
else:
|
| 51 |
manual_text = st.text_area("Paste requirement text here", height=200)
|
| 52 |
|
| 53 |
+
num_testcases = st.number_input("Approximate number of test cases to generate", min_value=1, max_value=50, value=10)
|
| 54 |
|
| 55 |
generate_btn = st.button("Generate Test Cases")
|
| 56 |
|
|
|
|
| 74 |
# ------------------------------
|
| 75 |
# Call Groq API to generate test cases
|
| 76 |
# ------------------------------
|
| 77 |
+
def call_groq_generate_testcases(text, num_testcases=10):
|
| 78 |
prompt = f"""
|
| 79 |
You are a QA expert. For the following requirement, generate approximately {num_testcases} detailed test cases in the following clean format:
|
| 80 |
|
|
|
|
| 89 |
Expected Result: <Expected Result>
|
| 90 |
====================================================
|
| 91 |
|
| 92 |
+
ONLY return the test cases in this clean format with lines separating each test case. Do not include anything else.
|
| 93 |
Requirement:
|
| 94 |
\"\"\"{text}\"\"\"
|
| 95 |
"""
|
| 96 |
response = client.chat.completions.create(
|
| 97 |
model="llama-3.1-8b-instant",
|
| 98 |
messages=[{"role":"user", "content": prompt}],
|
| 99 |
+
max_tokens=1500
|
| 100 |
)
|
| 101 |
return response.choices[0].message.content
|
| 102 |
|
|
|
|
| 104 |
# Generate test cases
|
| 105 |
# ------------------------------
|
| 106 |
if generate_btn:
|
|
|
|
| 107 |
if input_method == "Upload File":
|
| 108 |
if uploaded_file is not None:
|
| 109 |
try:
|
|
|
|
| 128 |
st.error(f"Error generating test cases: {e}")
|
| 129 |
st.stop()
|
| 130 |
|
|
|
|
| 131 |
st.subheader("🔸 Generated Test Cases")
|
| 132 |
+
with st.expander("View Test Cases", expanded=True):
|
| 133 |
+
st.code(testcases_output, language="text") # Shows output in a neat code block
|
|
|
|
|
|
|
| 134 |
|
|
|
|
| 135 |
st.download_button(
|
| 136 |
"Download Test Cases as TXT",
|
| 137 |
testcases_output,
|