Spaces:
Sleeping
Sleeping
| 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) | |