Spaces:
Running
Running
Commit
·
51402aa
1
Parent(s):
1879bed
Add application file
Browse files- README.md +15 -4
- app.py +54 -0
- requirements.txt +5 -0
README.md
CHANGED
|
@@ -1,12 +1,23 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🏢
|
| 4 |
colorFrom: red
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.0.2
|
| 8 |
app_file: app.py
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Typhoon 2.5 Qwen3 4B
|
| 3 |
emoji: 🏢
|
| 4 |
colorFrom: red
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.0.2
|
| 8 |
app_file: app.py
|
| 9 |
+
hf_oauth: true
|
| 10 |
+
hf_oauth_expiration_minutes: 480
|
| 11 |
+
suggested_hardware: zero-a10g
|
| 12 |
+
license: apache-2.0
|
| 13 |
---
|
| 14 |
|
| 15 |
+
รันบน Hugging Face Spaces พร้อม UI ด้วย Gradio
|
| 16 |
+
|
| 17 |
+
## วิธีใช้งาน
|
| 18 |
+
- พิมพ์ข้อความภาษาไทยในช่อง Input
|
| 19 |
+
- กด Submit
|
| 20 |
+
- รอ Model ตอบกลับ
|
| 21 |
+
|
| 22 |
+
## โมเดลที่ใช้
|
| 23 |
+
- https://huggingface.co/scb10x/typhoon2.5-qwen3-4b
|
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
+
import spaces
|
| 6 |
+
|
| 7 |
+
model_name = "scb10x/typhoon2.5-qwen3-4b"
|
| 8 |
+
token = os.getenv("HF_TOKEN")
|
| 9 |
+
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 11 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 12 |
+
model_name,
|
| 13 |
+
trust_remote_code=True,
|
| 14 |
+
torch_dtype=torch.float16,
|
| 15 |
+
low_cpu_mem_usage=True,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
model.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
+
|
| 20 |
+
def generate_chat(message):
|
| 21 |
+
messages = [{"role": "user", "content": message}]
|
| 22 |
+
|
| 23 |
+
input_ids = tokenizer.apply_chat_template(
|
| 24 |
+
messages,
|
| 25 |
+
add_generation_prompt=True,
|
| 26 |
+
return_tensors="pt"
|
| 27 |
+
).to(model.device)
|
| 28 |
+
|
| 29 |
+
output_ids = model.generate(
|
| 30 |
+
input_ids,
|
| 31 |
+
max_new_tokens=256,
|
| 32 |
+
temperature=0.7,
|
| 33 |
+
do_sample=True,
|
| 34 |
+
top_p=0.9,
|
| 35 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 39 |
+
response_text = response.split(message)[-1].strip()
|
| 40 |
+
|
| 41 |
+
return response_text
|
| 42 |
+
|
| 43 |
+
@spaces.GPU
|
| 44 |
+
def predict(message, history=None):
|
| 45 |
+
response = generate_chat(message)
|
| 46 |
+
return response
|
| 47 |
+
|
| 48 |
+
chat_ui = gr.ChatInterface(
|
| 49 |
+
fn=predict,
|
| 50 |
+
title="Typhoon 2.5 ZeroGPU",
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
chat_ui.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
accelerate
|
| 3 |
+
gradio
|
| 4 |
+
torch
|
| 5 |
+
spaces
|