''' GRADIO APP ''' import os import gradio as gr import openai ''' ######################### Environment Variables ######################### ''' # Read OpenAI API key from environment variable openai.api_key = os.getenv("OPENAI_API_KEY") if not openai.api_key: st.error("No OpenAI API key found in the environment variable OPENAI_API_KEY") ''' ##################### Backend Functions ##################### ''' 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. "}] 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"}] 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"}] def generate_test_cases(topic): if topic: conversation_tc.append({"role": "user", "content": f"Generate a manual test case for the topic: {topic}"}) response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=conversation_tc ) test_cases = response["choices"][0]["message"]["content"] return test_cases else: return "Please enter a topic/subject." def generate_test_scripts(framework, test_cases): print("TEST SCRIPT", framework) if framework == "Python, unittest": print("py") return generate_python_unittest(test_cases) elif framework == "Java, JUnit": print("java") return generate_java_junit(test_cases) else: return "Unsupported language or framework." def generate_python_unittest(test_cases): convo_py.append({"role": "user", "content": f"Here is a manual test case. {test_cases}"}) # prompt = f"Create a Python unittest test script for the following test cases:\n{test_cases}" response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=convo_py ) script = response["choices"][0]["message"]["content"] return script def generate_java_junit(test_cases): convo_java.append({"role": "user", "content": f"Here is a manual test case. {test_cases}"}) # prompt = f"Create a Java JUnit test script for the following test cases:\n{test_cases}" response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=convo_java ) script = response["choices"][0]["message"]["content"] return script ''' ##################### Markdown Content ##################### ''' title = """ # QA Leveraging GenAI """ description = ''' 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. By inputting a functional use case, you can generate detailed test cases to ensure the quality of your software. You can also select your preferred testing framework, and the tool will generate test scripts based on the generated test cases