Initial upload from AmkyawDev-LLM-V3
Browse files- README.md +36 -0
- deployment/web_ui/README.md +16 -0
- deployment/web_ui/app.py +225 -0
- deployment/web_ui/requirements.txt +15 -0
- scripts/push_space.py +53 -0
- training/config.yaml +1 -1
README.md
CHANGED
|
@@ -96,6 +96,42 @@ python scripts/push_to_hub.py
|
|
| 96 |
|
| 97 |
MIT License
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
## π Acknowledgments
|
| 100 |
|
| 101 |
- [TRL](https://github.com/huggingface/trl) - SFTTrainer
|
|
|
|
| 96 |
|
| 97 |
MIT License
|
| 98 |
|
| 99 |
+
## π Deploy to Hugging Face Spaces
|
| 100 |
+
|
| 101 |
+
### Option 1: Create Space via UI
|
| 102 |
+
1. Go to: https://huggingface.co/spaces
|
| 103 |
+
2. Click "Create new Space"
|
| 104 |
+
3. Select "Gradio" as SDK
|
| 105 |
+
4. Upload the `deployment/web_ui/` folder contents
|
| 106 |
+
5. Add required secrets (HF Token if needed)
|
| 107 |
+
|
| 108 |
+
### Option 2: Push to Space programmatically
|
| 109 |
+
|
| 110 |
+
```python
|
| 111 |
+
from huggingface_hub import HfApi, login
|
| 112 |
+
|
| 113 |
+
login(token="your_hf_token")
|
| 114 |
+
|
| 115 |
+
api = HfApi()
|
| 116 |
+
api.create_repo(
|
| 117 |
+
repo_id="amkyawdev/AmkyawDev-LLM-V3",
|
| 118 |
+
repo_type="space",
|
| 119 |
+
space_sdk="gradio"
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
api.upload_folder(
|
| 123 |
+
folder_path="deployment/web_ui",
|
| 124 |
+
repo_id="amkyawdev/AmkyawDev-LLM-V3",
|
| 125 |
+
repo_type="space",
|
| 126 |
+
)
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
### Space Configuration
|
| 130 |
+
The Space uses:
|
| 131 |
+
- **SDK**: Gradio
|
| 132 |
+
- **Python**: 3.10+
|
| 133 |
+
- **Hardware**: CPU (or GPU if using Pro subscription)
|
| 134 |
+
|
| 135 |
## π Acknowledgments
|
| 136 |
|
| 137 |
- [TRL](https://github.com/huggingface/trl) - SFTTrainer
|
deployment/web_ui/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AmkyawDev-LLM-V3 Space Configuration
|
| 2 |
+
|
| 3 |
+
title: AmkyawDev-LLM-V3
|
| 4 |
+
emoji: π²π²
|
| 5 |
+
colorFrom: blue
|
| 6 |
+
colorTo: green
|
| 7 |
+
sdk: gradio
|
| 8 |
+
sdk_version: 4.0.0
|
| 9 |
+
app_file: app.py
|
| 10 |
+
pinned: false
|
| 11 |
+
license: mit
|
| 12 |
+
tags:
|
| 13 |
+
- burmese
|
| 14 |
+
- language-model
|
| 15 |
+
- llama
|
| 16 |
+
- fine-tuned
|
deployment/web_ui/app.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
AmkyawDev-LLM-V3 Gradio Web UI
|
| 4 |
+
Burmese Language Model Chat Interface
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import torch
|
| 9 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoPeftModel
|
| 10 |
+
from peft import PeftModel, PeftConfig
|
| 11 |
+
import gradio as gr
|
| 12 |
+
from threading import Thread
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# Model Configuration
|
| 16 |
+
BASE_MODEL = "Qwen/Qwen2.5-1.5B-Instruct" # Qwen2.5-1.5B model
|
| 17 |
+
ADAPTER_PATH = "./model/adapter" # Path to your LoRA weights
|
| 18 |
+
|
| 19 |
+
# Load model and tokenizer
|
| 20 |
+
def load_model():
|
| 21 |
+
"""Load the fine-tuned model with LoRA adapters."""
|
| 22 |
+
|
| 23 |
+
print("Loading tokenizer...")
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 25 |
+
BASE_MODEL,
|
| 26 |
+
trust_remote_code=True
|
| 27 |
+
)
|
| 28 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 29 |
+
|
| 30 |
+
print("Loading base model...")
|
| 31 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 32 |
+
BASE_MODEL,
|
| 33 |
+
trust_remote_code=True,
|
| 34 |
+
torch_dtype=torch.float16,
|
| 35 |
+
device_map="auto",
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Check if adapter exists
|
| 39 |
+
if os.path.exists(ADAPTER_PATH) and os.listdir(ADAPTER_PATH):
|
| 40 |
+
print("Loading LoRA adapter...")
|
| 41 |
+
model = PeftModel.from_pretrained(
|
| 42 |
+
base_model,
|
| 43 |
+
ADAPTER_PATH,
|
| 44 |
+
torch_dtype=torch.float16,
|
| 45 |
+
)
|
| 46 |
+
else:
|
| 47 |
+
print("No adapter found, using base model.")
|
| 48 |
+
model = base_model
|
| 49 |
+
|
| 50 |
+
model.eval()
|
| 51 |
+
|
| 52 |
+
return model, tokenizer
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# Initialize model globally
|
| 56 |
+
print("Initializing model... This may take a few minutes.")
|
| 57 |
+
try:
|
| 58 |
+
model, tokenizer = load_model()
|
| 59 |
+
print("Model loaded successfully!")
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f"Error loading model: {e}")
|
| 62 |
+
print("Running in demo mode with mock responses.")
|
| 63 |
+
model = None
|
| 64 |
+
tokenizer = None
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def generate_response(prompt, system_prompt=None, temperature=0.7, max_tokens=512):
|
| 68 |
+
"""Generate response from the model."""
|
| 69 |
+
|
| 70 |
+
if model is None:
|
| 71 |
+
# Demo mode - return mock response
|
| 72 |
+
return "π α€αααΊααΎα¬ demo mode ααΌα
αΊαα«αααΊα αα±α¬αΊαααΊαα«ααΊααΊααα«αα²α·α‘αα½ααΊα
ααΊαΈαααΊααΌα±ααα―αα«αααΊα"
|
| 73 |
+
|
| 74 |
+
# Build conversation
|
| 75 |
+
if system_prompt:
|
| 76 |
+
full_prompt = f"System: {system_prompt}\n\nUser: {prompt}\nAssistant:"
|
| 77 |
+
else:
|
| 78 |
+
full_prompt = f"User: {prompt}\nAssistant:"
|
| 79 |
+
|
| 80 |
+
# Tokenize
|
| 81 |
+
inputs = tokenizer(full_prompt, return_tensors="pt").to(model.device)
|
| 82 |
+
|
| 83 |
+
# Generate
|
| 84 |
+
with torch.no_grad():
|
| 85 |
+
outputs = model.generate(
|
| 86 |
+
**inputs,
|
| 87 |
+
temperature=temperature,
|
| 88 |
+
max_new_tokens=max_tokens,
|
| 89 |
+
do_sample=True,
|
| 90 |
+
top_p=0.9,
|
| 91 |
+
repetition_penalty=1.1,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# Decode response
|
| 95 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 96 |
+
|
| 97 |
+
# Extract assistant response
|
| 98 |
+
if "Assistant:" in response:
|
| 99 |
+
response = response.split("Assistant:")[-1].strip()
|
| 100 |
+
|
| 101 |
+
return response
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def chat(message, history, system_prompt, temperature, max_tokens):
|
| 105 |
+
"""Chat function for Gradio."""
|
| 106 |
+
|
| 107 |
+
response = generate_response(
|
| 108 |
+
message,
|
| 109 |
+
system_prompt=system_prompt,
|
| 110 |
+
temperature=temperature,
|
| 111 |
+
max_tokens=max_tokens
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
return response
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# Build Gradio Interface
|
| 118 |
+
def create_ui():
|
| 119 |
+
"""Create the Gradio web UI."""
|
| 120 |
+
|
| 121 |
+
with gr.Blocks(
|
| 122 |
+
title="AmkyawDev-LLM-V3",
|
| 123 |
+
theme=gr.themes.Soft(),
|
| 124 |
+
css="""
|
| 125 |
+
.gradio-container {max-width: 1200px !important;}
|
| 126 |
+
.main {background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);}
|
| 127 |
+
"""
|
| 128 |
+
) as demo:
|
| 129 |
+
|
| 130 |
+
gr.Markdown("""
|
| 131 |
+
# π²π² AmkyawDev-LLM-V3
|
| 132 |
+
### Burmese Language Model Chat Interface
|
| 133 |
+
|
| 134 |
+
α€αααΊααΎα¬ ααΌααΊαα¬αα¬αα¬α
αα¬αΈ Large Language Model ααΌα
αΊαα«αααΊα
|
| 135 |
+
""")
|
| 136 |
+
|
| 137 |
+
with gr.Row():
|
| 138 |
+
with gr.Column(scale=3):
|
| 139 |
+
chatbot = gr.Chatbot(
|
| 140 |
+
height=500,
|
| 141 |
+
show_copy_button=True,
|
| 142 |
+
bubble_full_width=False,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
with gr.Row():
|
| 146 |
+
msg = gr.Textbox(
|
| 147 |
+
label="Message",
|
| 148 |
+
placeholder="αα±αΈαα½ααΊαΈααα―ααΊαα«αααΊ...",
|
| 149 |
+
lines=3,
|
| 150 |
+
container=True,
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
with gr.Row():
|
| 154 |
+
submit_btn = gr.Button("π€ ααα―α·αααΊ", variant="primary")
|
| 155 |
+
clear_btn = gr.Button("ποΈ ααΎααΊαΈαααΊ", variant="secondary")
|
| 156 |
+
|
| 157 |
+
with gr.Column(scale=1):
|
| 158 |
+
gr.Markdown("### βοΈ Settings")
|
| 159 |
+
|
| 160 |
+
system_prompt = gr.Textbox(
|
| 161 |
+
label="System Prompt",
|
| 162 |
+
value="You are a helpful Burmese language assistant.",
|
| 163 |
+
lines=3,
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
temperature = gr.Slider(
|
| 167 |
+
label="Temperature",
|
| 168 |
+
minimum=0.1,
|
| 169 |
+
maximum=1.5,
|
| 170 |
+
value=0.7,
|
| 171 |
+
step=0.1,
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
max_tokens = gr.Slider(
|
| 175 |
+
label="Max Tokens",
|
| 176 |
+
minimum=64,
|
| 177 |
+
maximum=2048,
|
| 178 |
+
value=512,
|
| 179 |
+
step=64,
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
# Chat functionality
|
| 183 |
+
def respond(message, history, system_prompt, temperature, max_tokens):
|
| 184 |
+
response = generate_response(
|
| 185 |
+
message,
|
| 186 |
+
system_prompt=system_prompt,
|
| 187 |
+
temperature=temperature,
|
| 188 |
+
max_tokens=max_tokens
|
| 189 |
+
)
|
| 190 |
+
history.append((message, response))
|
| 191 |
+
return "", history
|
| 192 |
+
|
| 193 |
+
submit_btn.click(
|
| 194 |
+
respond,
|
| 195 |
+
inputs=[msg, chatbot, system_prompt, temperature, max_tokens],
|
| 196 |
+
outputs=[msg, chatbot],
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
msg.submit(
|
| 200 |
+
respond,
|
| 201 |
+
inputs=[msg, chatbot, system_prompt, temperature, max_tokens],
|
| 202 |
+
outputs=[msg, chatbot],
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
clear_btn.click(lambda: (None, [])), outputs=[msg, chatbot])
|
| 206 |
+
|
| 207 |
+
gr.Markdown("""
|
| 208 |
+
---
|
| 209 |
+
### π Notes
|
| 210 |
+
- αα±α¬αΊαααΊααα«αα«α demo mode ααΌα
αΊααα«αααΊα
|
| 211 |
+
- LoRA weights αα«αα»ααΊαΈααα―ααΊαΈαα«αααΊα
|
| 212 |
+
""")
|
| 213 |
+
|
| 214 |
+
return demo
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
# Main
|
| 218 |
+
if __name__ == "__main__":
|
| 219 |
+
print("Starting AmkyawDev-LLM-V3 Web UI...")
|
| 220 |
+
demo = create_ui()
|
| 221 |
+
demo.launch(
|
| 222 |
+
server_name="0.0.0.0",
|
| 223 |
+
server_port=7860,
|
| 224 |
+
share=False,
|
| 225 |
+
)
|
deployment/web_ui/requirements.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AmkyawDev-LLM-V3 Web UI Requirements
|
| 2 |
+
|
| 3 |
+
# Core ML
|
| 4 |
+
torch>=2.0.0
|
| 5 |
+
transformers>=4.36.0
|
| 6 |
+
|
| 7 |
+
# PEFT for LoRA
|
| 8 |
+
peft>=0.8.0
|
| 9 |
+
|
| 10 |
+
# Web UI
|
| 11 |
+
gradio>=4.0.0
|
| 12 |
+
|
| 13 |
+
# Additional
|
| 14 |
+
accelerate>=0.25.0
|
| 15 |
+
numpy>=1.24.0
|
scripts/push_space.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Push AmkyawDev-LLM-V3 to Hugging Face Spaces
|
| 4 |
+
Creates a Gradio Space for the Burmese Language Model
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
from huggingface_hub import HfApi, login
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def create_space():
|
| 12 |
+
"""Create and push the Gradio Space to Hugging Face."""
|
| 13 |
+
|
| 14 |
+
# Get token from environment
|
| 15 |
+
token = os.environ.get("HF_TOKEN")
|
| 16 |
+
|
| 17 |
+
if not token:
|
| 18 |
+
print("Error: No Hugging Face token found.")
|
| 19 |
+
print("Please set HF_TOKEN environment variable")
|
| 20 |
+
return
|
| 21 |
+
|
| 22 |
+
# Login
|
| 23 |
+
print("Logging in to Hugging Face...")
|
| 24 |
+
login(token=token)
|
| 25 |
+
|
| 26 |
+
# Initialize API
|
| 27 |
+
api = HfApi()
|
| 28 |
+
|
| 29 |
+
repo_id = "amkyawdev/AmkyawDev-LLM-V3"
|
| 30 |
+
|
| 31 |
+
# Create Space repository
|
| 32 |
+
print(f"Creating Space: {repo_id}")
|
| 33 |
+
api.create_repo(
|
| 34 |
+
repo_id=repo_id,
|
| 35 |
+
repo_type="space",
|
| 36 |
+
space_sdk="gradio",
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Upload files to Space
|
| 40 |
+
print("Uploading web_ui files to Space...")
|
| 41 |
+
api.upload_folder(
|
| 42 |
+
folder_path="deployment/web_ui",
|
| 43 |
+
repo_id=repo_id,
|
| 44 |
+
repo_type="space",
|
| 45 |
+
commit_message="Initial Space upload"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
print(f"β
Successfully created Space!")
|
| 49 |
+
print(f" URL: https://huggingface.co/spaces/{repo_id}")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
create_space()
|
training/config.yaml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
|
| 3 |
# Model Configuration
|
| 4 |
model:
|
| 5 |
-
name: "
|
| 6 |
trust_remote_code: true
|
| 7 |
|
| 8 |
# LoRA Configuration
|
|
|
|
| 2 |
|
| 3 |
# Model Configuration
|
| 4 |
model:
|
| 5 |
+
name: "Qwen/Qwen2.5-1.5B-Instruct" # Qwen2.5-1.5B model
|
| 6 |
trust_remote_code: true
|
| 7 |
|
| 8 |
# LoRA Configuration
|