File size: 1,171 Bytes
853a750
 
 
 
 
 
 
c37ddf6
853a750
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24f8784
853a750
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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-7B-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)