Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435361 unmodified line383940414243444546474849504 unmodified lines55565758596061626364656667import gradio as grimport torchfrom transformers import AutoTokenizer, AutoModelForCausalLM, pipelineimport traceback# ๐ ุงุณุชุฎุฏู ู ูุฏููู ุงูุชMODEL_NAME = "kawkabelaloom/astramindx"SYSTEM_PROMPT = "ุฃูุช ู ุณุงุนุฏ ุนุฑุจู ุฐููุ ุชุฌูุจ ุจูุถูุญ ูุจุฃุณููุจ ุจุณูุท ูู ููุฏ."print("๐ Loading tokenizer...")tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME,trust_remote_code=True)print("๐ Loading model (CPU)...")model = AutoModelForCausalLM.from_pretrained(MODEL_NAME,device_map="cpu",torch_dtype=torch.float32,low_cpu_mem_usage=True,trust_remote_code=True)print("โ Model loaded")generator = pipeline("text-generation",model=model,tokenizer=tokenizer)def build_prompt(history, user_message):prompt = SYSTEM_PROMPT + "\n\n"for user, bot in history:1 unmodified lineprompt += f"ุงูู ุณุชุฎุฏู : {user_message}\nุงูู ุณุงุนุฏ:"return promptdef chat(user_message, history):try:prompt = build_prompt(history, user_message)output = generator(prompt,max_new_tokens=128, # ๐ ููููุง ููุณุฑุนุฉtemperature=0.7,top_p=0.9,do_sample=True4 unmodified linesreturn history, ""except Exception as e:history.append((user_message, str(e)))return history, ""with gr.Blocks() as demo:gr.Markdown("# ๐ค Astramindx Chatbot")chatbot = gr.Chatbot(height=450)msg = gr.Textbox()msg.submit(chat, [msg, chatbot], [chatbot, msg])demo.launch()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950511 unmodified line53545556575859606162636465664 unmodified lines71727374757677787980818283848586import gradio as grimport torchfrom transformers import AutoTokenizer, AutoModelForCausalLM, pipeline# =========================# CONFIG# =========================MODEL_NAME = "kawkabelaloom/astramindx"SYSTEM_PROMPT = "ุฃูุช ู ุณุงุนุฏ ุนุฑุจู ุฐููุ ุชุฌูุจ ุจูุถูุญ ูุจุฃุณููุจ ุจุณูุท ูู ููุฏ."# =========================# LOAD TOKENIZER# =========================print("๐ Loading tokenizer...")tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME,trust_remote_code=True)# =========================# LOAD MODEL (FORCE CPU โ NO QUANTIZATION)# =========================print("๐ Loading model (CPU, no quantization)...")model = AutoModelForCausalLM.from_pretrained(MODEL_NAME,device_map=None, # โ ูุง device_map autotorch_dtype=torch.float32, # CPU safelow_cpu_mem_usage=False, # ู ููtrust_remote_code=True,quantization_config=None # ๐ฅ ุงูุญู ุงูุฃุณุงุณู)model.eval()print("โ Model loaded successfully")# =========================# PIPELINE# =========================generator = pipeline("text-generation",model=model,tokenizer=tokenizer)# =========================# CHAT LOGIC# =========================def build_prompt(history, user_message):prompt = SYSTEM_PROMPT + "\n\n"for user, bot in history:1 unmodified lineprompt += f"ุงูู ุณุชุฎุฏู : {user_message}\nุงูู ุณุงุนุฏ:"return promptdef chat(user_message, history):try:prompt = build_prompt(history, user_message)output = generator(prompt,max_new_tokens=128,temperature=0.7,top_p=0.9,do_sample=True4 unmodified linesreturn history, ""except Exception as e:history.append((user_message, f"โ Error: {str(e)}"))return history, ""# =========================# GRADIO UI# =========================with gr.Blocks() as demo:gr.Markdown("# ๐ค Astramindx Chatbot")chatbot = gr.Chatbot(height=450)msg = gr.Textbox(placeholder="ุงูุชุจ ุณุคุงูู ููุง...")msg.submit(chat, [msg, chatbot], [chatbot, msg])demo.launch()
app.py+31-12