Spaces:
Runtime error
Runtime error
File size: 976 Bytes
6f375db f586e35 9e2903c db612f3 6f375db 9f3ddb8 9e2903c 9f3ddb8 bcbf840 9e2903c 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 44 45 46 47 48 | import gradio as gr
from transformers import pipeline
generator = pipeline(
"text-generation",
model="deepseek-ai/deepseek-coder-1.3b-instruct",
device_map="auto".
clean_up_tokenization_spaces=True
)
SYSTEM_PROMPT = """
You are a senior Python engineer.
When answering:
- Return clean Python code
- Follow best practices
- Keep functions simple
- Add comments if 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("Ġ", " ")
code = output.split("Assistant:")[-1]
return f"```python\n{code}\n```"
demo = gr.ChatInterface(
fn=chat,
title="Python Coding Assistant",
description="Ask Python coding questions"
)
demo.launch() |