Spaces:
Sleeping
Sleeping
File size: 974 Bytes
853a750 c37ddf6 853a750 f2b45ff 853a750 f2b45ff 853a750 3e7c552 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 |
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):
# Generate code based on the input prompt
output = code_writer(prompt, 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=5, placeholder="Enter a description or snippet for code generation.")
],
outputs=[gr.Textbox(label="Generated Code", lines=10)],
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)
|