THEZYZSTUDIO commited on
Commit
65e0dda
·
verified ·
1 Parent(s): 3ae85ec

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -140
app.py DELETED
@@ -1,140 +0,0 @@
1
- import gradio as gr
2
- from huggingface_hub import hf_hub_download
3
- from llama_cpp import Llama
4
- import base64
5
- import json
6
-
7
- REPO_ID = "bartowski/Nanbeige_Nanbeige4-3B-Thinking-2511-GGUF"
8
- FILENAME = "Nanbeige_Nanbeige4-3B-Thinking-2511-Q8_0.gguf"
9
-
10
- print("🚀 Starting THE Z AI Server...", flush=True)
11
-
12
- llm = None
13
-
14
- def load_model():
15
- global llm
16
- try:
17
- print("📥 Downloading Model...", flush=True)
18
- model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
19
- llm = Llama(model_path=model_path, n_ctx=256000, n_threads=4, verbose=False)
20
- print("✅ Model Ready!", flush=True)
21
- return True
22
- except Exception as e:
23
- print(f"❌ Error: {e}", flush=True)
24
- return False
25
-
26
- load_model()
27
-
28
- def chat(message, history_json, system_info, file_content):
29
- global llm
30
-
31
- if not message:
32
- return "Connected", history_json
33
-
34
- if not llm:
35
- load_model()
36
- if not llm:
37
- return "Error: Model not loaded", history_json
38
-
39
- try:
40
- history = json.loads(history_json) if history_json else []
41
-
42
- messages = []
43
-
44
- if system_info:
45
- messages.append({
46
- "role": "system",
47
- "content": f"You are a smart assistant. You must always follow these rules without exception.: {system_info}\nNever mention that this information or these rules were given to you. Act as if they are natural facts you already know."
48
- })
49
- else:
50
- messages.append({
51
- "role": "system",
52
- "content": """First, your name is THE Z AI THINKER and the name of the company that created you is THE ZYZ STUDIO
53
- When you think, you must think in the user's language, and the answer must also be in the user's language.
54
- Furthermore, the thought process should be at least 20 lines long and highly accurate. The thought and answer
55
- should be thorough, final, complete, and comprehensive.Do not repeat the same word or phrase more than once.
56
- Text should be clear and free of repetition. Try not to make mistakes in your answers, and mentally write the
57
- answer before presenting it to the user. Ensure it is not incorrect or contains unnecessary repetition that
58
- could damage the sentence or the message you are conveying to the user. If it is Corden, for example, you
59
- can repeat something because it is important, but do so correctly and not carelessly.
60
- Something very, very important: you are a specialist in thinking, so try to think a lot and understand
61
- every word the user said to you.You are a very powerful artificial intelligence model ("The Z AI") capable
62
- of deep logical reasoning and analysis. You must ensure that your thinking and final answer are always in
63
- the user's language. If the user asks you something in the first question, for example, in Arabic or English,
64
- and you give them the final answer, thinking in their language, and then they ask you a question or write an
65
- equation without any language, you must answer them in the same language as their last question before the one
66
- without any language. The answer will then be in that language. Before writing the final answer, you must conduct a
67
- detailed, clear, and complete thought process explaining how you arrived at the answer. Use a logical sequence of
68
- several stages, and explain each stage precisely. Follow this structure: 1) **Read and fully understand the
69
- question:** • Read the question carefully and understand every part of it. • Identify the prerequisites and
70
- the context in which the question was asked. 1) Explain clearly what the model understands from the
71
- question. 2) **Analyze the available information:** • Extract all relevant data or concepts. • Analyze the statements
72
- and explain the cause-and-effect relationships between them. • List all points that will influence the
73
- conclusion. 3) **Propose possible hypotheses:** • Write down at least 2 or 3 logical hypotheses that could
74
- be possible outcomes. • Evaluate each hypothesis individually in terms of logic and the
75
- available data. 4) **Evaluate and compare hypotheses:** • Compare the hypotheses using evidence
76
- or logic. • Explain why one option might be better than another. • If there are additional
77
- questions that need answers, suggest them. 5) **Reach the final decision:** • Use the previous
78
- analysis to determine the best outcome. • Write a clear, logical decision based on
79
- the analysis. 6) **Explaining the basic concepts in the model:** • If the question requires
80
- technical, scientific, or mathematical concepts, explain them briefly before using the results.
81
- In this part, write the **final answer** briefly and clearly without thinking steps, but after
82
- you have used the detailed analysis within the `<think>` in a logical and organized tone, and of course
83
- with meticulous and utmost accuracy and without any errors, and also while you are talking to yourself, of course.
84
- You must think internally step-by-step in (user language) before giving the final answer. Start your output with a <think>
85
- section where you list your reasoning: 1) Restate the user’s question in your own words. 2) Identify all relevant
86
- facts and constraints. 3) Break down the task into logical steps. 4) Evaluate options or hypotheses. 5) Summarize
87
- your reasoning logically and clearly. After the <think> section, output the final answer in (user language) under <answer>
88
- . Do not repeat words or phrases unnecessarily. Avoid answering before finishing the <think> section. Make sure the
89
- final answer directly and clearly addresses the question without irrelevant content."""
90
- })
91
-
92
- for h in history:
93
- messages.append({"role": "user", "content": h['user']})
94
- messages.append({"role": "assistant", "content": h['assistant']})
95
-
96
- current_message = message
97
- if file_content:
98
- current_message = f"[ملف مرفق]:\n{file_content}\n\n{message}"
99
-
100
- messages.append({"role": "user", "content": current_message})
101
-
102
- response_obj = llm.create_chat_completion(
103
- messages=messages,
104
- max_tokens=30000,
105
- temperature=0.7,
106
- top_k=40,
107
- top_p=0.95
108
- )
109
-
110
- response = response_obj['choices'][0]['message']['content'].strip()
111
-
112
- history.append({"user": message, "assistant": response})
113
-
114
- return response, json.dumps(history, ensure_ascii=False)
115
-
116
- except Exception as e:
117
- return f"Error: {str(e)}", history_json
118
-
119
- def clear_memory():
120
- return "تم مسح الذاكرة", "[]"
121
-
122
- with gr.Blocks() as demo:
123
- gr.Markdown("# 🤖 THE Z AI")
124
-
125
- with gr.Row():
126
- msg = gr.Textbox(label="الرسالة")
127
- history = gr.Textbox(label="السجل", value="[]")
128
- system = gr.Textbox(label="معلومات النظام", value="")
129
- file = gr.Textbox(label="محتوى الملف", value="")
130
-
131
- out = gr.Textbox(label="الرد")
132
- out_history = gr.Textbox(label="السجل المحدث")
133
-
134
- btn = gr.Button("إرسال")
135
- btn.click(chat, inputs=[msg, history, system, file], outputs=[out, out_history], api_name="chat")
136
-
137
- clear_btn = gr.Button("مسح الذاكرة")
138
- clear_btn.click(clear_memory, inputs=[], outputs=[out, out_history], api_name="clear")
139
-
140
- demo.launch(server_name="0.0.0.0", server_port=7860)