Remove unused tokenizer initialization and related comments in app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import os
|
| 5 |
-
from transformers import AutoTokenizer
|
| 6 |
|
| 7 |
# โหลดตัวแปรจาก .env
|
| 8 |
load_dotenv()
|
|
@@ -13,9 +12,6 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
| 13 |
|
| 14 |
# สร้าง InferenceClient ด้วย token
|
| 15 |
client = InferenceClient("iapp/chinda-qwen3-4b", token=HF_TOKEN)
|
| 16 |
-
# โหลด tokenizer สำหรับ apply_chat_template
|
| 17 |
-
model_name = "iapp/chinda-qwen3-4b"
|
| 18 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 19 |
|
| 20 |
# ฟังก์ชันสำหรับประมวลผลข้อความสนทนา
|
| 21 |
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
|
|
@@ -28,10 +24,6 @@ def respond(message, history: list[tuple[str, str]], system_message, max_tokens,
|
|
| 28 |
messages.append({"role": "assistant", "content": bot_msg})
|
| 29 |
messages.append({"role": "user", "content": message})
|
| 30 |
|
| 31 |
-
# ใช้ tokenizer.apply_chat_template เพื่อเตรียม prompt (optional, เฉพาะถ้าต้องการปรับ prompt)
|
| 32 |
-
# text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=True)
|
| 33 |
-
# แต่ InferenceClient รองรับ messages โดยตรง
|
| 34 |
-
|
| 35 |
response = ""
|
| 36 |
# เรียกใช้งานแบบ streaming
|
| 37 |
for msg in client.chat_completion(
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
# โหลดตัวแปรจาก .env
|
| 7 |
load_dotenv()
|
|
|
|
| 12 |
|
| 13 |
# สร้าง InferenceClient ด้วย token
|
| 14 |
client = InferenceClient("iapp/chinda-qwen3-4b", token=HF_TOKEN)
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# ฟังก์ชันสำหรับประมวลผลข้อความสนทนา
|
| 17 |
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
|
|
|
|
| 24 |
messages.append({"role": "assistant", "content": bot_msg})
|
| 25 |
messages.append({"role": "user", "content": message})
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
response = ""
|
| 28 |
# เรียกใช้งานแบบ streaming
|
| 29 |
for msg in client.chat_completion(
|