Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Initialize the pipeline for code generation and assistance | |
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-Coder-32B-Instruct") | |
# Function to interact with the model for code-related assistance | |
def code_assistance(user_input): | |
# Define the system message to set the context | |
system_message = "You are Qwen, a code assistant created by Alibaba Cloud. You assist with code generation, debugging, and explanation tasks." | |
# Format the prompt with the system message and user input (code-related query) | |
prompt = f"{system_message}\nUser: {user_input}\nAssistant (Code Assistance):" | |
# Use the pipeline to generate the response for code assistance | |
response = pipe(prompt, max_length=512, num_return_sequences=1) | |
# Extract and clean the response to return only the assistant's code suggestion or explanation | |
generated_response = response[0]['generated_text'].split("Assistant (Code Assistance):")[1].strip() | |
return generated_response | |
# Create the Gradio interface for the code assistance chatbot | |
iface = gr.Interface( | |
fn=code_assistance, | |
inputs=gr.Textbox(lines=5, placeholder="Ask for code help..."), | |
outputs="text", | |
title="Qwen2.5-Coder Chatbot", | |
description="A chatbot using Qwen2.5-Coder for code generation, debugging, and explanation tasks." | |
) | |
# Launch the Gradio interface | |
iface.launch() | |