import gradio as gr from huggingface_hub import InferenceClient # Initialize the Qwen client client = InferenceClient("Qwen/Qwen2.5-Coder") def generate_code(prompt): messages = [ {"role": "system", "content": "You are an expert Python developer who creates clean, efficient code."}, {"role": "user", "content": f"Create a Python tool for the following requirement: {prompt}"} ] response = client.text_generation( messages, max_new_tokens=1024, temperature=0.7, top_p=0.9, repetition_penalty=1.1 ) return response["generated_text"] # Create the Gradio interface with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple")) as demo: gr.Markdown("# 🛠️ AI Tool Builder by Syncmerce") gr.Markdown("Enter your tool requirements and get production-ready Python code!") with gr.Row(): with gr.Column(): prompt_input = gr.Textbox( label="Tool Requirements", placeholder="Describe the tool you want to build...", lines=4 ) generate_btn = gr.Button("Generate Tool", variant="primary") with gr.Column(): code_output = gr.Code( label="Generated Code", language="python", lines=20 ) generate_btn.click( fn=generate_code, inputs=prompt_input, outputs=code_output ) gr.Markdown("### Examples:") gr.Examples( [ ["Create a PDF text extractor tool that can process multiple files"], ["Build a web scraper that extracts product prices from e-commerce sites"], ["Make a tool for batch image resizing with a progress bar"] ], inputs=prompt_input ) demo.launch()