Spaces:
Runtime error
Runtime error
Download app.py from raghualgt/python-coding-assistant: direct link, hf CLI and curl.
- Browser
- Download file 861 Bytes
-
https://huggingface.co/spaces/raghualgt/python-coding-assistant/resolve/db612f3265dc2155016c0ed237a56ec9b8d72084/app.py
- Command line
-
hf download hf://spaces/raghualgt/python-coding-assistant@db612f3265dc2155016c0ed237a56ec9b8d72084/app.py
-
curl -L -o app.py https://huggingface.co/spaces/raghualgt/python-coding-assistant/resolve/db612f3265dc2155016c0ed237a56ec9b8d72084/app.py
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() |