""" Gradio Space: Python docstring generation. HF runs the app; do not call demo.launch() here. """ import gradio as gr def summarize_code(code: str) -> str: if not code or not code.strip(): return "Paste a Python code snippet above." try: from inference import generate_docstring return generate_docstring(code, model_name="t5-small", max_length=128, num_beams=4) except Exception as e: return f"Error: {str(e)}. (Model may be loading; try again.)" demo = gr.Interface( fn=summarize_code, inputs=gr.Textbox( label="Python code", placeholder="def add(a, b):\n return a + b", lines=8, ), outputs=gr.Textbox(label="Generated docstring"), title="Python Docstring Generator", description="Paste a Python function or snippet to get a short docstring summary.", ) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)