Spaces:
Runtime error
Runtime error
File size: 861 Bytes
6f375db db612f3 6f375db 9f3ddb8 bcbf840 9f3ddb8 6f375db | 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 33 34 35 36 37 38 39 40 41 42 43 | 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() |