Spaces:
Sleeping
Sleeping
File size: 2,351 Bytes
d5f7564 a6a5465 14e4a92 a6a5465 d5f7564 a6a5465 315b0b5 a6a5465 a40ec6a a6a5465 a40ec6a a6a5465 a40ec6a a6a5465 d5f7564 a6a5465 14e4a92 a6a5465 026025c a6a5465 14e4a92 a6a5465 14e4a92 a6a5465 14e4a92 a6a5465 14e4a92 a6a5465 14e4a92 d5f7564 a6a5465 026025c a6a5465 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import logging
from transformers import pipeline
import gradio as gr
# Set up logging
logging.basicConfig(
filename="app.log",
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s"
)
# Load the generative AI model
logging.info("Loading the Hugging Face model...")
try:
model = pipeline("text2text-generation", model="google/flan-t5-large") # Replace with your chosen model
logging.info("Model loaded successfully.")
except Exception as e:
logging.error(f"Error loading the model: {e}")
raise
# Function to generate test cases
def generate_test_cases(api_info):
logging.info(f"Generating test cases for API info: {api_info}")
try:
prompt = (
f"Generate API test cases for the following API:\n\n{api_info}\n\n"
f"Test cases should include:\n- Happy path\n- Negative tests\n- Edge cases"
)
result = model(prompt, max_length=512, num_return_sequences=1)
logging.info(f"Test cases generated successfully.")
return result[0]['generated_text']
except Exception as e:
logging.error(f"Error generating test cases: {e}")
return "An error occurred while generating test cases."
# Process input and generate output
def process_input(url, method, headers, payload):
try:
logging.info("Received user input.")
api_info = f"URL: {url}\nMethod: {method}\nHeaders: {headers}\nPayload: {payload}"
logging.debug(f"Formatted API info: {api_info}")
test_cases = generate_test_cases(api_info)
return test_cases
except Exception as e:
logging.error(f"Error processing input: {e}")
return "An error occurred. Please check the input format and try again."
# Define Gradio interface
interface = gr.Interface(
fn=process_input,
inputs=[
gr.Textbox(label="API URL"),
gr.Textbox(label="HTTP Method"),
gr.Textbox(label="Headers (JSON format)"),
gr.Textbox(label="Payload (JSON format)"),
],
outputs="text",
title="API Test Case Generator"
)
# Launch Gradio app
if __name__ == "__main__":
try:
logging.info("Starting the Gradio app...")
interface.launch()
logging.info("Gradio app launched successfully.")
except Exception as e:
logging.error(f"Error launching the Gradio app: {e}")
|