Update app.py
Browse files
app.py
CHANGED
|
@@ -130,19 +130,51 @@ def generate_local_qwen(language, kpis, task):
|
|
| 130 |
is_ar = language != "en"
|
| 131 |
lang = "Arabic" if is_ar else "English"
|
| 132 |
|
|
|
|
| 133 |
if task == "insights":
|
| 134 |
key = "insights"
|
| 135 |
-
schema = (
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
system = (
|
| 138 |
f"You are a careful KPI performance analyst. Reply in {lang}. "
|
| 139 |
-
"Use only supplied data
|
| 140 |
-
|
| 141 |
-
"
|
| 142 |
-
"
|
| 143 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
)
|
| 145 |
-
user = "Analyze the current KPI values, targets, statuses and recent history. KPI data:\n" + json.dumps(kpis, ensure_ascii=False)
|
| 146 |
else:
|
| 147 |
key = "indicators"
|
| 148 |
schema = ('{"indicators":[{"kpi_name":"...","description":"...",'
|
|
|
|
| 130 |
is_ar = language != "en"
|
| 131 |
lang = "Arabic" if is_ar else "English"
|
| 132 |
|
| 133 |
+
|
| 134 |
if task == "insights":
|
| 135 |
key = "insights"
|
| 136 |
+
schema = (
|
| 137 |
+
'{"insights":['
|
| 138 |
+
'{"title":"...","finding":"...",'
|
| 139 |
+
'"evidence":"...","recommendation":"..."},'
|
| 140 |
+
'{"title":"...","finding":"...",'
|
| 141 |
+
'"evidence":"...","recommendation":"..."},'
|
| 142 |
+
'{"title":"...","finding":"...",'
|
| 143 |
+
'"evidence":"...","recommendation":"..."}'
|
| 144 |
+
']}'
|
| 145 |
+
)
|
| 146 |
system = (
|
| 147 |
f"You are a careful KPI performance analyst. Reply in {lang}. "
|
| 148 |
+
"Use only the supplied data. Never invent figures, trends, causes, "
|
| 149 |
+
"or facts. Return valid JSON only, matching the exact schema. "
|
| 150 |
+
"Return exactly 3 insights in this order: improvement, alert, recommendation. "
|
| 151 |
+
"The title is already displayed separately in the user interface. "
|
| 152 |
+
"For Arabic, titles must be exactly: تحسين ملحوظ, تنبيه, توصية. "
|
| 153 |
+
"For English, titles must be exactly: Notable Improvement, Alert, Recommendation. "
|
| 154 |
+
"Do not repeat the title inside the finding. "
|
| 155 |
+
"For each insight, write finding as a natural, concise sentence that uses "
|
| 156 |
+
"the KPI's actual human-readable kpi_name, never its technical kpi_id. "
|
| 157 |
+
"For example, say 'تحسين رضا المتعاملين' instead of 'KPI_01'. "
|
| 158 |
+
"Do not include KPI IDs in finding, evidence, or recommendation unless "
|
| 159 |
+
"absolutely necessary to distinguish indicators. "
|
| 160 |
+
"The evidence field must begin with 'الدليل من البيانات:' in Arabic "
|
| 161 |
+
"or 'Evidence from the data:' in English, followed by specific supplied "
|
| 162 |
+
"values, dates, or trends. "
|
| 163 |
+
"The recommendation field must begin with 'الإجراء المقترح:' in Arabic "
|
| 164 |
+
"or 'Suggested action:' in English, followed by a practical action. "
|
| 165 |
+
"Keep the labels inside evidence and recommendation because they are part "
|
| 166 |
+
"of the desired response format. "
|
| 167 |
+
"For the improvement insight, describe the actual improvement and its values. "
|
| 168 |
+
"For the alert insight, describe the concern or state that data is insufficient. "
|
| 169 |
+
"For the recommendation insight, provide a useful action grounded in the data. "
|
| 170 |
+
"Do not add Markdown headings or extra fields. "
|
| 171 |
+
"Keep all statements concise, readable, and actionable."
|
| 172 |
+
)
|
| 173 |
+
user = (
|
| 174 |
+
"Analyze the current KPI values, targets, statuses and recent history. "
|
| 175 |
+
"Use the human-readable kpi_name in the analysis, not kpi_id. "
|
| 176 |
+
"KPI data:\n" + json.dumps(kpis, ensure_ascii=False)
|
| 177 |
)
|
|
|
|
| 178 |
else:
|
| 179 |
key = "indicators"
|
| 180 |
schema = ('{"indicators":[{"kpi_name":"...","description":"...",'
|