Code_Generator / app.py
ANASAKHTAR's picture
Update app.py
24f8784 verified
raw
history blame
1.17 kB
import torch
import gradio as gr
from transformers import pipeline
# Use a pipeline as a high-level helper
from transformers import pipeline
code_writer = pipeline("text-generation", model="Qwen/Qwen2.5-Coder-32B-Instruct",torch_dtype=torch.bfloat16 )
# Define the code generation function
def generate_code(prompt, max_length):
# Generate code based on the input prompt and maximum length
output = code_writer(prompt, max_length=max_length, num_return_sequences=1, do_sample=True)
return output[0]['generated_text']
# Close any existing Gradio instances
gr.close_all()
# Set up the Gradio interface
Demo = gr.Interface(
fn=generate_code,
inputs=[
gr.Textbox(label="Code Prompt", lines=10, placeholder="Enter a description or snippet for code generation."),
gr.Slider(
label="Code Length (Tokens Approx.)",
minimum=10, maximum=13000, step=1000, value=150
)
],
outputs=[gr.Textbox(label="Generated Code", lines=20)],
title="Code_Generator_App",
description="This application generates code based on your input prompt."
)
# Launch the app with a public link
Demo.launch(share=True)