Spaces:
Sleeping
Sleeping
revert to old version
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
''' GRADIO APP '''
|
2 |
|
3 |
-
import os
|
4 |
import gradio as gr
|
5 |
import openai
|
6 |
|
@@ -12,8 +12,7 @@ import openai
|
|
12 |
#########################
|
13 |
'''
|
14 |
# Read OpenAI API key from environment variable
|
15 |
-
openai.api_key = "
|
16 |
-
# openai.api_key = os.getenv("OPENAI_API_KEY")
|
17 |
|
18 |
if not openai.api_key:
|
19 |
st.error("No OpenAI API key found in the environment variable OPENAI_API_KEY")
|
@@ -25,32 +24,25 @@ if not openai.api_key:
|
|
25 |
#####################
|
26 |
'''
|
27 |
|
28 |
-
|
29 |
convo_py = [{"role": "system", "content": "You are a technical and a professional QA manager who specializes in Python Unittest, working in a technological firm. You should provide Python Unittest test scripts in for the test case provided"}]
|
30 |
convo_java = [{"role": "system", "content": "You are a technical and a professional QA manager who specializes in Java JUnit, working in a technological firm. You should provide Java JUnit test scripts in for the test case provided"}]
|
31 |
|
32 |
|
33 |
-
def generate_test_cases(
|
34 |
-
if ctx:
|
35 |
-
conversation_tc = json.loads(ctx)
|
36 |
-
print(conversation_tc)
|
37 |
if topic:
|
38 |
conversation_tc.append({"role": "user", "content": f"Generate a manual test case for the topic: {topic}"})
|
39 |
-
print("Request to OpenAI", conversation_tc)
|
40 |
response = openai.ChatCompletion.create(
|
41 |
model="gpt-3.5-turbo",
|
42 |
messages=conversation_tc
|
43 |
)
|
44 |
-
|
45 |
test_cases = response["choices"][0]["message"]["content"]
|
46 |
-
return test_cases
|
47 |
else:
|
48 |
return "Please enter a topic/subject."
|
49 |
|
50 |
-
def generate_test_scripts(
|
51 |
-
if ctx:
|
52 |
-
convo_py = json.loads(ctx)
|
53 |
-
convo_java = json.loads(ctx)
|
54 |
print("TEST SCRIPT", framework)
|
55 |
if framework == "Python, unittest":
|
56 |
print("py")
|
@@ -96,7 +88,7 @@ title = """
|
|
96 |
description = '''
|
97 |
This tool leverages OpenAI's GPT-3.5-turbo model to automate two key aspects of quality assurance in software development: generating test cases and writing test scripts.
|
98 |
|
99 |
-
By
|
100 |
You can also select your preferred testing framework, and the tool will generate test scripts based on the generated test cases
|
101 |
<hr>
|
102 |
'''
|
@@ -131,45 +123,30 @@ This tool is produced by an LLM and therefore the outputs might not be perfect.
|
|
131 |
Gradio Block
|
132 |
#####################
|
133 |
'''
|
134 |
-
|
135 |
-
test_case_2 = None
|
136 |
|
137 |
with gr.Blocks() as demo:
|
138 |
-
|
139 |
-
|
140 |
gr.Markdown(title)
|
141 |
gr.Markdown(description)
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
value='[{"role": "system", "content": "You are a technical and a professional QA manager who specializes in Python Unittest, working in a technological firm. You should provide Python Unittest test scripts in for the test case provided"}]')
|
160 |
-
with gr.Row():
|
161 |
-
with gr.Column():
|
162 |
-
fw = gr.Dropdown(["Python, unittest", "Java, JUnit"], label="Framework")
|
163 |
-
test_case_2 = gr.Textbox(label="Test Case", lines=20, interactive=True)
|
164 |
-
ts_button = gr.Button("Generate Test Script")
|
165 |
-
with gr.Column():
|
166 |
-
test_script = gr.Code(label="Test Script",language="python")
|
167 |
-
|
168 |
-
|
169 |
-
tc_button.click(fn=generate_test_cases, inputs=[test_case_context,test_case_topic], outputs=[test_case_1,test_case_2], show_progress=True)
|
170 |
-
ts_button.click(fn=generate_test_scripts, inputs=[test_script_context, fw, test_case_2], outputs=test_script, show_progress=True)
|
171 |
|
172 |
# gr.Markdown(howto)
|
173 |
gr.Markdown(notices)
|
174 |
|
175 |
-
demo.queue(api_open=False, max_size=5).launch(
|
|
|
1 |
''' GRADIO APP '''
|
2 |
|
3 |
+
import os
|
4 |
import gradio as gr
|
5 |
import openai
|
6 |
|
|
|
12 |
#########################
|
13 |
'''
|
14 |
# Read OpenAI API key from environment variable
|
15 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
16 |
|
17 |
if not openai.api_key:
|
18 |
st.error("No OpenAI API key found in the environment variable OPENAI_API_KEY")
|
|
|
24 |
#####################
|
25 |
'''
|
26 |
|
27 |
+
conversation_tc = [{"role": "system", "content": "You are a technical and a professional QA manager, working in a technological firm. You provide test cases for a scenario. "}]
|
28 |
convo_py = [{"role": "system", "content": "You are a technical and a professional QA manager who specializes in Python Unittest, working in a technological firm. You should provide Python Unittest test scripts in for the test case provided"}]
|
29 |
convo_java = [{"role": "system", "content": "You are a technical and a professional QA manager who specializes in Java JUnit, working in a technological firm. You should provide Java JUnit test scripts in for the test case provided"}]
|
30 |
|
31 |
|
32 |
+
def generate_test_cases(topic):
|
|
|
|
|
|
|
33 |
if topic:
|
34 |
conversation_tc.append({"role": "user", "content": f"Generate a manual test case for the topic: {topic}"})
|
|
|
35 |
response = openai.ChatCompletion.create(
|
36 |
model="gpt-3.5-turbo",
|
37 |
messages=conversation_tc
|
38 |
)
|
39 |
+
|
40 |
test_cases = response["choices"][0]["message"]["content"]
|
41 |
+
return test_cases
|
42 |
else:
|
43 |
return "Please enter a topic/subject."
|
44 |
|
45 |
+
def generate_test_scripts(framework, test_cases):
|
|
|
|
|
|
|
46 |
print("TEST SCRIPT", framework)
|
47 |
if framework == "Python, unittest":
|
48 |
print("py")
|
|
|
88 |
description = '''
|
89 |
This tool leverages OpenAI's GPT-3.5-turbo model to automate two key aspects of quality assurance in software development: generating test cases and writing test scripts.
|
90 |
|
91 |
+
By inputting a functional use case, you can generate detailed test cases to ensure the quality of your software.
|
92 |
You can also select your preferred testing framework, and the tool will generate test scripts based on the generated test cases
|
93 |
<hr>
|
94 |
'''
|
|
|
123 |
Gradio Block
|
124 |
#####################
|
125 |
'''
|
126 |
+
test_case = None
|
|
|
127 |
|
128 |
with gr.Blocks() as demo:
|
|
|
|
|
129 |
gr.Markdown(title)
|
130 |
gr.Markdown(description)
|
131 |
|
132 |
+
|
133 |
+
with gr.Row() as text_to_image:
|
134 |
+
|
135 |
+
with gr.Column():
|
136 |
+
test_case_topic = gr.Textbox(label='Functional Usecase', value='VR Headset Battery Installation', info="Descriptive usecase to generate Test Cases for")
|
137 |
+
tc_button = gr.Button("Generate Test Case")
|
138 |
+
test_case = gr.Textbox(label="Test Case")
|
139 |
+
|
140 |
+
with gr.Column():
|
141 |
+
fw = gr.Dropdown(["Python, unittest", "Java, JUnit"], label="Framework", info="Framework to generate test scripts on"),
|
142 |
+
ts_button = gr.Button("Generate Test Script")
|
143 |
+
test_script = gr.Textbox(label="Test Script")
|
144 |
+
|
145 |
+
|
146 |
+
tc_button.click(fn=generate_test_cases, inputs=test_case_topic, outputs=test_case, show_progress=True)
|
147 |
+
ts_button.click(fn=generate_test_scripts, inputs=[fw[0], test_case], outputs=test_script, show_progress=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
# gr.Markdown(howto)
|
150 |
gr.Markdown(notices)
|
151 |
|
152 |
+
demo.queue(api_open=False, max_size=5).launch()
|