Spaces:
Sleeping
Sleeping
allow context setting
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,7 +12,8 @@ import openai
|
|
12 |
#########################
|
13 |
'''
|
14 |
# Read OpenAI API key from environment variable
|
15 |
-
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 +25,32 @@ if not 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,7 +96,7 @@ title = """
|
|
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
|
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,30 +131,45 @@ This tool is produced by an LLM and therefore the outputs might not be perfect.
|
|
123 |
Gradio Block
|
124 |
#####################
|
125 |
'''
|
126 |
-
|
|
|
127 |
|
128 |
with gr.Blocks() as demo:
|
|
|
|
|
129 |
gr.Markdown(title)
|
130 |
gr.Markdown(description)
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
# gr.Markdown(howto)
|
150 |
gr.Markdown(notices)
|
151 |
|
152 |
-
demo.queue(api_open=False, max_size=5).launch()
|
|
|
1 |
''' GRADIO APP '''
|
2 |
|
3 |
+
import os, json
|
4 |
import gradio as gr
|
5 |
import openai
|
6 |
|
|
|
12 |
#########################
|
13 |
'''
|
14 |
# Read OpenAI API key from environment variable
|
15 |
+
openai.api_key = "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"
|
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 |
#####################
|
26 |
'''
|
27 |
|
28 |
+
# 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. "}]
|
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(ctx, topic):
|
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 |
+
print("Response from OpenAI", response["usage"]["total_tokens"])
|
45 |
test_cases = response["choices"][0]["message"]["content"]
|
46 |
+
return test_cases, test_cases
|
47 |
else:
|
48 |
return "Please enter a topic/subject."
|
49 |
|
50 |
+
def generate_test_scripts(ctx, framework, test_cases):
|
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 |
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 providing a functional use case, you can generate detailed test cases to ensure the quality of your software.
|
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 |
Gradio Block
|
132 |
#####################
|
133 |
'''
|
134 |
+
test_case_1 = None
|
135 |
+
test_case_2 = None
|
136 |
|
137 |
with gr.Blocks() as demo:
|
138 |
+
|
139 |
+
|
140 |
gr.Markdown(title)
|
141 |
gr.Markdown(description)
|
142 |
|
143 |
+
with gr.Tab("1. Text Generation"):
|
144 |
+
with gr.Accordion("Context"):
|
145 |
+
test_case_context = gr.Textbox(label='Functional Usecase',
|
146 |
+
open=False,
|
147 |
+
value='[{"role": "system", "content": "You are a technical and a professional QA manager, working in a technological firm. You provide test cases for a scenario. "}]')
|
148 |
+
with gr.Row():
|
149 |
+
with gr.Column():
|
150 |
+
test_case_topic = gr.Textbox(label='Functional Usecase', value='Robotic arm to test payments using card with driver, inspector and billing device')
|
151 |
+
tc_button = gr.Button("Generate Test Case")
|
152 |
+
with gr.Column():
|
153 |
+
test_case_1 = gr.Textbox(label="Test Case")
|
154 |
+
|
155 |
+
with gr.Tab("2. Test Script Generation"):
|
156 |
+
with gr.Accordion("Context"):
|
157 |
+
test_script_context = gr.Textbox(label='Functional Usecase',
|
158 |
+
open=False,
|
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(debug=True)
|