Team Ai
Apppublic

alirezaaminzadeh/python-docstring-generator

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
app.py29 linesDownload Raw Back to root
1"""2Gradio Space: Python docstring generation.3HF runs the app; do not call demo.launch() here.4"""5import gradio as gr6 7def summarize_code(code: str) -> str:8    if not code or not code.strip():9        return "Paste a Python code snippet above."10    try:11        from inference import generate_docstring12        return generate_docstring(code, model_name="t5-small", max_length=128, num_beams=4)13    except Exception as e:14        return f"Error: {str(e)}. (Model may be loading; try again.)"15 16demo = gr.Interface(17    fn=summarize_code,18    inputs=gr.Textbox(19        label="Python code",20        placeholder="def add(a, b):\n    return a + b",21        lines=8,22    ),23    outputs=gr.Textbox(label="Generated docstring"),24    title="Python Docstring Generator",25    description="Paste a Python function or snippet to get a short docstring summary.",26)27if __name__ == "__main__":28    demo.launch(server_name="0.0.0.0", server_port=7860)29