1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_id = "mahmut2142/alimzeka-gemma-reasoning"
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
6
7# Example Usage Flow
8import torch
9from transformers import AutoModelForCausalLM, AutoProcessor, TextIteratorStreamer
10import threading, os
11os.environ["PYTORCH_ALLOC_CONF"] = "expandable_segments:True"
12
13model_id = "................................."
14
15SYSTEM_PROMPT = (
16 "You are ALIMZEKA — an academic research assistant specialized in Islamic sciences "
17 "and general knowledge. Your task is to provide accurate, source-based, and professional "
18 "responses in accordance with the principles of the Quran, Sunnah, and Ijma. "
19 "If a topic is unknown or disputed, you clearly state this; you do not produce "
20 "unsupported, unsourced, or unverified Arabic text. At the end of every answer, "
21 "you include a Confidence Score (High/Medium/Low) and conclude your statements "
22 "with 'Allah knows best.' Before answering, you must always analyze complex issues "
23 "step by step within a chain-of-thought (<thought>...</thought>). "
24 "STRICT RULE: After completing the reasoning process, you MUST close the </thought> tag "
25 "and then provide the user with a detailed final answer! It is FORBIDDEN to respond "
26 "with only the reasoning process."
27)
28
29print("\n==================================")
30print(" ALIMZEKA Terminal Chat Test")
31print(f" Model: {model_id}")
32print("==================================\n")
33
34print("⏳ Loading processor...")
35processor = AutoProcessor.from_pretrained(model_id)
36if processor.tokenizer.pad_token is None:
37 processor.tokenizer.pad_token = processor.tokenizer.eos_token
38
39print("⏳ Loading model (bfloat16 + 4-bit quantization)...")
40from transformers import BitsAndBytesConfig
41bnb = BitsAndBytesConfig(
42 load_in_4bit=True,
43 bnb_4bit_compute_dtype=torch.bfloat16,
44 bnb_4bit_use_double_quant=True,
45 bnb_4bit_quant_type="nf4",
46)
47model = AutoModelForCausalLM.from_pretrained(
48 model_id,
49 device_map="auto",
50 quantization_config=bnb,
51 torch_dtype=torch.bfloat16,
52)
53model.eval()
54
55print("\n✅ System Ready. Type 'exit' or 'quit' to leave.\n")
56
57while True:
58 try:
59 user_input = input("\nYou: ")
60 if user_input.lower() in ['exit', 'quit', 'çıkış']:
61 break
62 if not user_input.strip():
63 continue
64
65 messages = [
66 {"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]},
67 {"role": "user", "content": [{"type": "text", "text": user_input}]},
68 ]
69
70 inputs = processor.apply_chat_template(
71 messages,
72 add_generation_prompt=True,
73 tokenize=True,
74 return_dict=True,
75 return_tensors="pt",
76 ).to(model.device)
77
78 for k, v in inputs.items():
79 if torch.is_floating_point(v):
80 inputs[k] = v.to(model.dtype)
81
82 streamer = TextIteratorStreamer(processor.tokenizer, skip_prompt=True, skip_special_tokens=True)
83 t = threading.Thread(
84 target=model.generate,
85 kwargs=dict(**inputs, streamer=streamer, max_new_tokens=3000,
86 do_sample=True, temperature=0.6, top_p=0.9),
87 )
88 t.start()
89
90 print("\nAlimZeka: ", end="", flush=True)
91 for chunk in streamer:
92 print(chunk, end="", flush=True)
93 t.join()
94 print()
95
96 except KeyboardInterrupt:
97 break
98
99print("\nExited.")
100
101⚖️ Legal Notice and Disclaimer
102AlimZeka is a technology development and academic research project. The responses generated by the model are analytical and supportive in nature; they should **not** be considered as definitive religious rulings (fatwas), legal judgments, or formal advice. Final decisions should always rely on qualified authorities and official sources.
103
104🛠️ Developer Information
105
106Lead Developer:Mahmut ERDEM
107
108Architecture: Google DeepMind Gemma 4
109
110License: Apache License 2.0