Upload folder using huggingface_hub
Browse files- README.md +39 -6
- app.py +87 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,12 +1,45 @@
|
|
| 1 |
---
|
| 2 |
-
title: Qwen Coder Assistant
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Qwen 2.5 Coder Assistant
|
| 3 |
+
emoji: 💻
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: Code assistant powered by fine-tuned Qwen 2.5 Coder
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Qwen 2.5 Coder Assistant
|
| 15 |
+
|
| 16 |
+
An interactive code assistant powered by a fine-tuned [Qwen 2.5 Coder 1.5B](https://huggingface.co/GhostScientist/qwen25-coder-1.5b-codealpaca-sft) model.
|
| 17 |
+
|
| 18 |
+
## Features
|
| 19 |
+
|
| 20 |
+
- **Code Generation**: Write functions, classes, and complete programs
|
| 21 |
+
- **Code Explanation**: Understand complex code snippets
|
| 22 |
+
- **Debugging Help**: Find and fix bugs in your code
|
| 23 |
+
- **Best Practices**: Get suggestions for code improvements
|
| 24 |
+
|
| 25 |
+
## Model Details
|
| 26 |
+
|
| 27 |
+
- **Base Model**: Qwen/Qwen2.5-Coder-1.5B-Instruct
|
| 28 |
+
- **Training**: Fine-tuned using SFT on CodeAlpaca dataset
|
| 29 |
+
- **Framework**: TRL + Transformers
|
| 30 |
+
|
| 31 |
+
## Usage
|
| 32 |
+
|
| 33 |
+
Simply type your coding question or request in the chat interface. You can:
|
| 34 |
+
|
| 35 |
+
1. Ask for code in any programming language
|
| 36 |
+
2. Paste code snippets for explanation or debugging
|
| 37 |
+
3. Request refactoring suggestions
|
| 38 |
+
4. Get help with algorithms and data structures
|
| 39 |
+
|
| 40 |
+
## Examples
|
| 41 |
+
|
| 42 |
+
- "Write a Python function to check if a number is prime"
|
| 43 |
+
- "Explain the difference between a list and a tuple in Python"
|
| 44 |
+
- "How do I reverse a string in JavaScript?"
|
| 45 |
+
- "Debug this code: def add(a, b): return a - b"
|
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
MODEL_ID = "GhostScientist/qwen25-coder-1.5b-codealpaca-sft"
|
| 5 |
+
|
| 6 |
+
client = InferenceClient(MODEL_ID)
|
| 7 |
+
|
| 8 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 9 |
+
"""Generate response using the fine-tuned Qwen coder model."""
|
| 10 |
+
messages = [{"role": "system", "content": system_message}]
|
| 11 |
+
|
| 12 |
+
for user_msg, assistant_msg in history:
|
| 13 |
+
if user_msg:
|
| 14 |
+
messages.append({"role": "user", "content": user_msg})
|
| 15 |
+
if assistant_msg:
|
| 16 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 17 |
+
|
| 18 |
+
messages.append({"role": "user", "content": message})
|
| 19 |
+
|
| 20 |
+
response = ""
|
| 21 |
+
for token in client.chat_completion(
|
| 22 |
+
messages,
|
| 23 |
+
max_tokens=max_tokens,
|
| 24 |
+
stream=True,
|
| 25 |
+
temperature=temperature,
|
| 26 |
+
top_p=top_p,
|
| 27 |
+
):
|
| 28 |
+
delta = token.choices[0].delta.content or ""
|
| 29 |
+
response += delta
|
| 30 |
+
yield response
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
SYSTEM_PROMPT = """You are an expert coding assistant. You help users write, debug, explain, and improve code.
|
| 34 |
+
You provide clear, concise, and accurate responses with well-formatted code examples when appropriate.
|
| 35 |
+
Always explain your reasoning and suggest best practices."""
|
| 36 |
+
|
| 37 |
+
EXAMPLES = [
|
| 38 |
+
"Write a Python function to check if a number is prime",
|
| 39 |
+
"Explain the difference between a list and a tuple in Python",
|
| 40 |
+
"How do I reverse a string in JavaScript?",
|
| 41 |
+
"Write a SQL query to find duplicate records in a table",
|
| 42 |
+
"Debug this code: def add(a, b): return a - b",
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
demo = gr.ChatInterface(
|
| 46 |
+
respond,
|
| 47 |
+
title="Qwen 2.5 Coder Assistant",
|
| 48 |
+
description="""A fine-tuned Qwen 2.5 Coder 1.5B model for code assistance.
|
| 49 |
+
Ask me to write code, explain concepts, debug issues, or help with any programming task!
|
| 50 |
+
|
| 51 |
+
**Model:** [GhostScientist/qwen25-coder-1.5b-codealpaca-sft](https://huggingface.co/GhostScientist/qwen25-coder-1.5b-codealpaca-sft)
|
| 52 |
+
""",
|
| 53 |
+
additional_inputs=[
|
| 54 |
+
gr.Textbox(
|
| 55 |
+
value=SYSTEM_PROMPT,
|
| 56 |
+
label="System Prompt",
|
| 57 |
+
lines=3
|
| 58 |
+
),
|
| 59 |
+
gr.Slider(
|
| 60 |
+
minimum=64,
|
| 61 |
+
maximum=2048,
|
| 62 |
+
value=512,
|
| 63 |
+
step=64,
|
| 64 |
+
label="Max Tokens"
|
| 65 |
+
),
|
| 66 |
+
gr.Slider(
|
| 67 |
+
minimum=0.1,
|
| 68 |
+
maximum=1.5,
|
| 69 |
+
value=0.7,
|
| 70 |
+
step=0.1,
|
| 71 |
+
label="Temperature"
|
| 72 |
+
),
|
| 73 |
+
gr.Slider(
|
| 74 |
+
minimum=0.1,
|
| 75 |
+
maximum=1.0,
|
| 76 |
+
value=0.95,
|
| 77 |
+
step=0.05,
|
| 78 |
+
label="Top-p"
|
| 79 |
+
),
|
| 80 |
+
],
|
| 81 |
+
examples=EXAMPLES,
|
| 82 |
+
cache_examples=False,
|
| 83 |
+
theme=gr.themes.Soft(),
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.44.0
|
| 2 |
+
huggingface_hub>=0.26.0
|