seed-image-ai commited on
Commit
d4aed0b
·
verified ·
1 Parent(s): eefbff2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -8
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 = ('{"insights":[{"title":"...","finding":"...",'
136
- '"evidence":"...","recommendation":"..."}]}')
 
 
 
 
 
 
 
 
137
  system = (
138
  f"You are a careful KPI performance analyst. Reply in {lang}. "
139
- "Use only supplied data; never invent figures, trends, causes or facts. "
140
- f"Return valid JSON only with schema {schema}. Exactly 3 insights in this order: "
141
- "notable improvement, alert, recommendation. For Arabic, titles must be exactly: "
142
- "تحسين ملحوظ, تنبيه, توصية. For English: Notable Improvement, Alert, Recommendation. "
143
- "Evidence must cite provided values or say data is insufficient. Keep each field concise and actionable."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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":"...",'