Upload folder using huggingface_hub
Browse files- .claude/settings.local.json +7 -0
- README.md +28 -6
- app.py +55 -0
- requirements.txt +2 -0
.claude/settings.local.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"permissions": {
|
| 3 |
+
"allow": [
|
| 4 |
+
"Skill(writing-skills:hugging-face-space-deployer)"
|
| 5 |
+
]
|
| 6 |
+
}
|
| 7 |
+
}
|
README.md
CHANGED
|
@@ -1,12 +1,34 @@
|
|
| 1 |
---
|
| 2 |
-
title: Qwen2.5 Coder
|
| 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: Qwen2.5 Coder 7B
|
| 3 |
+
emoji: 💻
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.9.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Qwen2.5 Coder 7B Chat
|
| 14 |
+
|
| 15 |
+
A coding assistant powered by [Qwen/Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct) via the Hugging Face Inference API.
|
| 16 |
+
|
| 17 |
+
## Features
|
| 18 |
+
|
| 19 |
+
- Streaming responses for real-time code generation
|
| 20 |
+
- Configurable system prompt, temperature, and other parameters
|
| 21 |
+
- Optimized for coding tasks including:
|
| 22 |
+
- Code generation and completion
|
| 23 |
+
- Code explanation and documentation
|
| 24 |
+
- Debugging and optimization
|
| 25 |
+
- Multi-language support
|
| 26 |
+
|
| 27 |
+
## Usage
|
| 28 |
+
|
| 29 |
+
Simply type your coding question or request in the chat interface. You can adjust the parameters:
|
| 30 |
+
|
| 31 |
+
- **System message**: Customize the assistant's behavior
|
| 32 |
+
- **Max tokens**: Control response length (up to 4096)
|
| 33 |
+
- **Temperature**: Adjust creativity (lower = more focused, higher = more creative)
|
| 34 |
+
- **Top-p**: Control diversity of responses
|
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
MODEL_ID = "Qwen/Qwen2.5-Coder-7B-Instruct"
|
| 5 |
+
client = InferenceClient(MODEL_ID)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 9 |
+
messages = [{"role": "system", "content": system_message}]
|
| 10 |
+
|
| 11 |
+
for user_msg, assistant_msg in history:
|
| 12 |
+
if user_msg:
|
| 13 |
+
messages.append({"role": "user", "content": user_msg})
|
| 14 |
+
if assistant_msg:
|
| 15 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 16 |
+
|
| 17 |
+
messages.append({"role": "user", "content": message})
|
| 18 |
+
|
| 19 |
+
response = ""
|
| 20 |
+
for token in client.chat_completion(
|
| 21 |
+
messages,
|
| 22 |
+
max_tokens=max_tokens,
|
| 23 |
+
stream=True,
|
| 24 |
+
temperature=temperature,
|
| 25 |
+
top_p=top_p,
|
| 26 |
+
):
|
| 27 |
+
delta = token.choices[0].delta.content or ""
|
| 28 |
+
response += delta
|
| 29 |
+
yield response
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
demo = gr.ChatInterface(
|
| 33 |
+
respond,
|
| 34 |
+
title="Qwen2.5 Coder 7B",
|
| 35 |
+
description="A coding assistant powered by Qwen2.5-Coder-7B-Instruct via Hugging Face Inference API",
|
| 36 |
+
additional_inputs=[
|
| 37 |
+
gr.Textbox(
|
| 38 |
+
value="You are Qwen, a helpful coding assistant. You excel at writing clean, efficient code and explaining programming concepts clearly.",
|
| 39 |
+
label="System message",
|
| 40 |
+
lines=2,
|
| 41 |
+
),
|
| 42 |
+
gr.Slider(minimum=1, maximum=4096, value=1024, step=1, label="Max tokens"),
|
| 43 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
|
| 44 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
| 45 |
+
],
|
| 46 |
+
examples=[
|
| 47 |
+
["Hello! What programming languages are you best at?"],
|
| 48 |
+
["Write a Python function to check if a string is a palindrome"],
|
| 49 |
+
["Explain the difference between async/await and promises in JavaScript"],
|
| 50 |
+
["Help me optimize this SQL query: SELECT * FROM users WHERE name LIKE '%john%'"],
|
| 51 |
+
],
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=5.0.0
|
| 2 |
+
huggingface_hub>=0.26.0
|