File size: 839 Bytes
3d94df2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import pipeline

# Load a lightweight test-case generation model
generator = pipeline("text2text-generation", model="Salesforce/codet5p-770m", max_length=512)

def generate_tests(code, instruction):
    prompt = f"Input:\n{code}\n\nInstruction:\n{instruction}"
    result = generator(prompt)[0]["generated_text"]
    return result

gr.Interface(
    fn=generate_tests,
    inputs=[
        gr.Textbox(label="Your Code", lines=10, placeholder="Paste your function here..."),
        gr.Textbox(label="Instruction", placeholder="e.g., Generate unit tests using Python unittest.")
    ],
    outputs=gr.Code(language="python"),
    title="🧪 Unit Test & Test Case Generator",
    description="🔧 Paste your function and get auto-generated test cases using a free model from Hugging Face."
).launch()