Spaces:
No application file
No application file
Update streamlit_app.py
Browse files- streamlit_app.py +19 -10
streamlit_app.py
CHANGED
|
@@ -1,15 +1,18 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from groq import Groq
|
|
|
|
| 3 |
import docx2txt
|
| 4 |
import PyPDF2
|
| 5 |
|
| 6 |
-
#
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# ------------------------------
|
| 9 |
# Streamlit page config and theme
|
| 10 |
# ------------------------------
|
| 11 |
st.set_page_config(page_title="🧪 TestCase Studio", layout="wide")
|
| 12 |
-
st.title("TestCase Studio")
|
| 13 |
|
| 14 |
# Custom CSS for clean theme
|
| 15 |
st.markdown(
|
|
@@ -20,12 +23,13 @@ st.markdown(
|
|
| 20 |
.stTextArea>div>div>textarea {font-size: 14px;}
|
| 21 |
.stFileUploader>div>div>label {font-weight: bold;}
|
| 22 |
.stExpanderHeader {font-weight: bold; font-size: 16px; color: #00796b;}
|
|
|
|
| 23 |
</style>
|
| 24 |
""",
|
| 25 |
unsafe_allow_html=True
|
| 26 |
)
|
| 27 |
|
| 28 |
-
st.write("Choose one input method to provide requirements:")
|
| 29 |
|
| 30 |
# ------------------------------
|
| 31 |
# Input method selection
|
|
@@ -40,7 +44,7 @@ if input_method == "Upload File":
|
|
| 40 |
else:
|
| 41 |
manual_text = st.text_area("Paste requirement text here", height=200)
|
| 42 |
|
| 43 |
-
num_testcases = st.number_input("Approximate number of test cases to generate", min_value=1, max_value=50, value=
|
| 44 |
|
| 45 |
generate_btn = st.button("Generate Test Cases")
|
| 46 |
|
|
@@ -64,7 +68,7 @@ def read_file(file):
|
|
| 64 |
# ------------------------------
|
| 65 |
# Call Groq API to generate test cases
|
| 66 |
# ------------------------------
|
| 67 |
-
def call_groq_generate_testcases(text, num_testcases=
|
| 68 |
prompt = f"""
|
| 69 |
You are a QA expert. For the following requirement, generate approximately {num_testcases} detailed test cases in the following clean format:
|
| 70 |
|
|
@@ -79,14 +83,14 @@ Steps:
|
|
| 79 |
Expected Result: <Expected Result>
|
| 80 |
====================================================
|
| 81 |
|
| 82 |
-
ONLY return the test cases in this clean format with
|
| 83 |
Requirement:
|
| 84 |
\"\"\"{text}\"\"\"
|
| 85 |
"""
|
| 86 |
response = client.chat.completions.create(
|
| 87 |
model="llama-3.1-8b-instant",
|
| 88 |
-
messages=[{"role":
|
| 89 |
-
max_tokens=
|
| 90 |
)
|
| 91 |
return response.choices[0].message.content
|
| 92 |
|
|
@@ -94,6 +98,7 @@ Requirement:
|
|
| 94 |
# Generate test cases
|
| 95 |
# ------------------------------
|
| 96 |
if generate_btn:
|
|
|
|
| 97 |
if input_method == "Upload File":
|
| 98 |
if uploaded_file is not None:
|
| 99 |
try:
|
|
@@ -118,10 +123,14 @@ if generate_btn:
|
|
| 118 |
st.error(f"Error generating test cases: {e}")
|
| 119 |
st.stop()
|
| 120 |
|
|
|
|
| 121 |
st.subheader("🔸 Generated Test Cases")
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
| 124 |
|
|
|
|
| 125 |
st.download_button(
|
| 126 |
"Download Test Cases as TXT",
|
| 127 |
testcases_output,
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from groq import Groq
|
| 3 |
+
import os
|
| 4 |
import docx2txt
|
| 5 |
import PyPDF2
|
| 6 |
|
| 7 |
+
# Hugging Face Secret for API key
|
| 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("🧪 TestCase Studio")
|
| 16 |
|
| 17 |
# Custom CSS for clean theme
|
| 18 |
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 **one input method** to provide requirements:")
|
| 33 |
|
| 34 |
# ------------------------------
|
| 35 |
# Input method selection
|
|
|
|
| 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=5)
|
| 48 |
|
| 49 |
generate_btn = st.button("Generate Test Cases")
|
| 50 |
|
|
|
|
| 68 |
# ------------------------------
|
| 69 |
# Call Groq API to generate test cases
|
| 70 |
# ------------------------------
|
| 71 |
+
def call_groq_generate_testcases(text, num_testcases=5):
|
| 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 |
Expected Result: <Expected Result>
|
| 84 |
====================================================
|
| 85 |
|
| 86 |
+
ONLY return the test cases in this clean format with single line separators.
|
| 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=2000
|
| 94 |
)
|
| 95 |
return response.choices[0].message.content
|
| 96 |
|
|
|
|
| 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 |
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 |
+
for block in testcases_output.split("===================================================="):
|
| 129 |
+
block = block.strip()
|
| 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,
|