Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Use a pipeline as a high-level helper
|
| 6 |
+
from transformers import pipeline
|
| 7 |
+
|
| 8 |
+
code_writer = pipeline("text-generation", model="Qwen/Qwen2.5-Coder-32B-Instruct",torch_dtype=torch.bfloat16 )
|
| 9 |
+
|
| 10 |
+
# Define the code generation function
|
| 11 |
+
def generate_code(prompt, max_length):
|
| 12 |
+
# Generate code based on the input prompt and maximum length
|
| 13 |
+
output = code_writer(prompt, max_length=max_length, num_return_sequences=1, do_sample=True)
|
| 14 |
+
return output[0]['generated_text']
|
| 15 |
+
|
| 16 |
+
# Close any existing Gradio instances
|
| 17 |
+
gr.close_all()
|
| 18 |
+
|
| 19 |
+
# Set up the Gradio interface
|
| 20 |
+
Demo = gr.Interface(
|
| 21 |
+
fn=generate_code,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.Textbox(label="Code Prompt", lines=10, placeholder="Enter a description or snippet for code generation."),
|
| 24 |
+
gr.Slider(
|
| 25 |
+
label="Code Length (Tokens Approx.)",
|
| 26 |
+
minimum=10, maximum=130000, step=1000, value=150
|
| 27 |
+
)
|
| 28 |
+
],
|
| 29 |
+
outputs=[gr.Textbox(label="Generated Code", lines=20)],
|
| 30 |
+
title="Code_Generator_App",
|
| 31 |
+
description="This application generates code based on your input prompt."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Launch the app with a public link
|
| 35 |
+
Demo.launch(share=True)
|
| 36 |
+
|