Spaces:
Runtime error
Runtime error
| 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() |