raghualgt's picture
Update app.py
db612f3 verified
Raw History Blame
861 Bytes
import gradio as gr
from transformers import pipeline
generator = pipeline(
"text-generation",
model="deepseek-ai/deepseek-coder-1.3b-instruct"
clean_up_tokenization_spaces=True
)
SYSTEM_PROMPT = """
You are an expert Python developer.
Always:
- write clean Python code
- add comments when useful
- avoid unnecessary explanations
"""
def chat(message, history):
prompt = SYSTEM_PROMPT + "\nUser: " + message + "\nAssistant:"
result = generator(
prompt,
max_new_tokens=200,
temperature=0.2
)
output = result[0]["generated_text"]
# Clean tokenizer artifacts
output = output.replace("Ċ", "\n").replace("Ġ", " ")
return output.split("Assistant:")[-1]
demo = gr.ChatInterface(
fn=chat,
title="Python Coding Assistant",
description="Ask Python coding questions"
)
demo.launch()