teoo33 commited on
Commit
3f1dfc5
·
verified ·
1 Parent(s): f35f433

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -38
app.py CHANGED
@@ -19,7 +19,7 @@ faq_output = ""
19
  business_info = None
20
  product_info = None
21
 
22
- # پرامپت مادر به‌عنوان دستورالعمل اصلی
23
  mother_prompt = """
24
  You are the Nova System, an innovative problem-solving approach implemented by a dynamic consortium of virtual experts, each serving a distinct role. Your goal is to assist the user in generating high-quality prompts, a comprehensive knowledge base, and an automatically generated Frequently Asked Questions (FAQ) section for chatbots.
25
 
@@ -28,17 +28,22 @@ The Nova System process is iterative and cyclical, involving the following key s
28
  1. **Receiving and Processing User Information Forms:** Process the information from the Business Information Form and Product/Service Information Form provided by the user.
29
  2. **Assigning Expert Roles:**
30
  - **Discussion Continuity Expert (DCE):** Manage and guide the process, provide instructions, summarize progress, and define goals for each iteration.
31
- - **Prompt Engineering Expert (PEE):** Generate initial drafts of chatbot prompt, knowledge base, and FAQ based on user information.
32
- - **Critical Analysis Expert (CAE):** Review and critique outputs, providing improvement suggestions.
 
 
 
33
  3. **Iterations and Expert Dialogue:** Conduct iterations with the following steps in Persian (Farsi):
34
  - **DCE's Instructions:** Provide instructions for PEE and CAE.
35
  - **PEE Output:** Generate or refine chatbot prompt, knowledge base, and FAQ.
36
  - **CAE Analysis:** Critique PEE outputs and suggest improvements.
37
  - **DCE Summary:** Summarize progress and set goals for the next iteration.
38
  4. **Iterate the Process:** Continue until high-quality outputs are achieved.
39
- 5. **Present the Final Outputs:** Final prompt in English with sections (Persona, Tone, Guidelines, etc.), knowledge base and FAQ in JSON-like format.
 
 
40
 
41
- Conduct all dialogues in Persian, but output the final prompt in English and knowledge base/FAQ in JSON-like format.
42
  """
43
 
44
  # تابع برای تبدیل داده‌ها به فرمت JSON-serializable
@@ -62,24 +67,25 @@ def process_excel_files(file1, file2):
62
  def start_process(file1, file2):
63
  global iteration_count, iteration_history, business_info, product_info
64
  iteration_count = 1
65
- iteration_history = "سلام! من سیستم نوا هستم، یک سیستم پیشرفته برای تولید پرامپت‌های چت‌بات، پایگاه دانش و FAQ خودکار. فرایند شروع شد.\n"
66
 
67
  # پردازش فایل‌ها
68
  business_info, product_info = process_excel_files(file1, file2)
69
  business_info_serializable = convert_to_serializable(business_info)
70
  product_info_serializable = convert_to_serializable(product_info)
71
 
72
- # مرحله ۱: دستورات DCE
73
- dce_instructions = f"iteration {iteration_count}: لطفاً بر اساس اطلاعات فرم‌ها، پرامپت اولیه، پایگاه دانش و FAQ رو تولید کنید."
74
  iteration_history += f"**دستورات DCE:** {dce_instructions}\n"
75
 
76
- # مرحله ۲: تولید توسط PEE
77
  pee_prompt = f"""
78
  {mother_prompt}
79
- شما Prompt Engineering Expert (PEE) هستید. بر اساس اطلاعات زیر، پرامپت اولیه چت‌بات، پایگاه دانش و FAQ رو به فارسی ت��لید کنید:
80
  اطلاعات کسب‌وکار: {json.dumps(business_info_serializable, ensure_ascii=False)}
81
  اطلاعات محصولات: {json.dumps(product_info_serializable, ensure_ascii=False)}
82
  {dce_instructions}
 
83
  """
84
  pee_response = client.chat.completions.create(
85
  model="gpt-4o",
@@ -88,10 +94,10 @@ def start_process(file1, file2):
88
  pee_output = pee_response.choices[0].message.content
89
  iteration_history += f"**خروجی PEE:**\n{pee_output}\n"
90
 
91
- # مرحله ۳: نقد توسط CAE
92
  cae_prompt = f"""
93
  {mother_prompt}
94
- شما Critical Analysis Expert (CAE) هستید. لطفاً خروجی PEE رو نقد کنید و پیشنهادات بهبود بدید:
95
  خروجی PEE:\n{pee_output}
96
  """
97
  cae_response = client.chat.completions.create(
@@ -101,13 +107,13 @@ def start_process(file1, file2):
101
  cae_output = cae_response.choices[0].message.content
102
  iteration_history += f"**نقد CAE:**\n{cae_output}\n"
103
 
104
- # مرحله ۴: جمع‌بندی DCE
105
  dce_summary = f"""
106
- **جمع‌بندی DCE:** iteration {iteration_count} با موفقیت انجام شد.
107
- **وضعیت فعلی:** پرامپت اولیه، پایگاه دانش و FAQ تولید شدند و نقد شدند.
108
- **اهداف iteration بعدی:**
109
- #G-{iteration_count}-1: بهبود پرامپت بر اساس نقد CAE.
110
- #G-{iteration_count}-2: تکمیل پایگاه دانش و FAQ.
111
  **پایان iteration {iteration_count}**
112
  """
113
  iteration_history += dce_summary
@@ -122,18 +128,19 @@ def continue_iteration():
122
  business_info_serializable = convert_to_serializable(business_info)
123
  product_info_serializable = convert_to_serializable(product_info)
124
 
125
- # مرحله ۱: دستورات DCE
126
- dce_instructions = f"iteration {iteration_count}: لطفاً خروجی قبلی رو بر اساس نقد CAE بهبود بدید و پرامپت، پایگاه دانش و FAQ رو بهینه کنید."
127
  iteration_history += f"**دستورات DCE:** {dce_instructions}\n"
128
 
129
- # مرحله ۲: تولید توسط PEE
130
  pee_prompt = f"""
131
  {mother_prompt}
132
- شما Prompt Engineering Expert (PEE) هستید. بر اساس تاریخچه و نقد قبلی، پرامپت، پایگاه دانش و FAQ رو بهبود بدید:
133
  اطلاعات کسب‌وکار: {json.dumps(business_info_serializable, ensure_ascii=False)}
134
  اطلاعات محصولات: {json.dumps(product_info_serializable, ensure_ascii=False)}
135
  تاریخچه iteration قبلی:\n{iteration_history}
136
  {dce_instructions}
 
137
  """
138
  pee_response = client.chat.completions.create(
139
  model="gpt-4o",
@@ -142,10 +149,10 @@ def continue_iteration():
142
  pee_output = pee_response.choices[0].message.content
143
  iteration_history += f"**خروجی PEE:**\n{pee_output}\n"
144
 
145
- # مرحله ۳: نقد توسط CAE
146
  cae_prompt = f"""
147
  {mother_prompt}
148
- شما Critical Analysis Expert (CAE) هستید. لطفاً خروجی جدید PEE رو نقد کنید و پیشنهادات بهبود بدید:
149
  خروجی PEE:\n{pee_output}
150
  """
151
  cae_response = client.chat.completions.create(
@@ -155,11 +162,11 @@ def continue_iteration():
155
  cae_output = cae_response.choices[0].message.content
156
  iteration_history += f"**نقد CAE:**\n{cae_output}\n"
157
 
158
- # مرحله ۴: جمع‌بندی DCE
159
  dce_summary = f"""
160
- **جمع‌بندی DCE:** iteration {iteration_count} انجام شد.
161
- **وضعیت فع��ی:** خروجی‌ها بهبود یافتند.
162
- **اهداف iteration بعدی:**
163
  #G-{iteration_count}-1: ادامه بهبود یا اتمام فرایند.
164
  **پایان iteration {iteration_count}**
165
  """
@@ -177,14 +184,14 @@ def end_process():
177
  # تولید خروجی نهایی
178
  final_prompt = f"""
179
  {mother_prompt}
180
- فرایند iteration‌ها تمام شده. لطفاً خروجی نهایی رو تولید کنید:
181
- - پرامپت چت‌بات به انگلیسی با بخش‌های: Persona, Tone, Guidelines, About Us, Responses to Common Questions, Contact Information, Additional Guidelines
182
- - پایگاه دانش به فرمت JSON-like
183
- - FAQ به فرمت JSON-like
184
  اطلاعات کسب‌وکار: {json.dumps(business_info_serializable, ensure_ascii=False)}
185
  اطلاعات محصولات: {json.dumps(product_info_serializable, ensure_ascii=False)}
186
  تاریخچه iteration‌ها:\n{iteration_history}
187
- لطفاً خروجی‌ها رو با --- از هم جدا کنید.
188
  """
189
  final_response = client.chat.completions.create(
190
  model="gpt-4o",
@@ -194,16 +201,16 @@ def end_process():
194
 
195
  # جداسازی خروجی‌ها
196
  parts = final_output.split("---")
197
- prompt_output = parts[0].strip() if len(parts) > 0 else "پرامپت تولید نشد"
198
- knowledge_base_output = parts[1].strip() if len(parts) > 1 else "پایگاه دانش تولید نشد"
199
- faq_output = parts[2].strip() if len(parts) > 2 else "FAQ تولید نشد"
200
 
201
- iteration_history += "\n**فرایند پایان یافت و خروجی نهایی تولید شد.**\n"
202
  return iteration_history, prompt_output, knowledge_base_output, faq_output
203
 
204
  # رابط کاربری Gradio
205
  with gr.Blocks() as demo:
206
- gr.Markdown("# سیستم نوا")
207
  with gr.Row():
208
  file1 = gr.File(label="فرم اطلاعات اولیه وردست")
209
  file2 = gr.File(label="فرم اطلاعات محصولات/خدمات")
 
19
  business_info = None
20
  product_info = None
21
 
22
+ # پرامپت مادر با جزئیات کامل
23
  mother_prompt = """
24
  You are the Nova System, an innovative problem-solving approach implemented by a dynamic consortium of virtual experts, each serving a distinct role. Your goal is to assist the user in generating high-quality prompts, a comprehensive knowledge base, and an automatically generated Frequently Asked Questions (FAQ) section for chatbots.
25
 
 
28
  1. **Receiving and Processing User Information Forms:** Process the information from the Business Information Form and Product/Service Information Form provided by the user.
29
  2. **Assigning Expert Roles:**
30
  - **Discussion Continuity Expert (DCE):** Manage and guide the process, provide instructions, summarize progress, and define goals for each iteration.
31
+ - **Prompt Engineering Expert (PEE):** Generate initial drafts of:
32
+ - Chatbot prompt in English with sections: Persona, Tone, Guidelines, About Us, Responses to Common Questions, Contact Information, Additional Guidelines. Tone must be friendly, casual, concise (under 100 words per response unless necessary), and use loving emojis.
33
+ - Knowledge base in JSON-like format with fields: name, description, variants (size and price), objectID.
34
+ - FAQ in JSON-like format with categories, topics, questions, and short, friendly answers.
35
+ - critical Analysis Expert (CAE):** Review and critique outputs, ensuring they match the desired tone, structure, and detail level, providing improvement suggestions.
36
  3. **Iterations and Expert Dialogue:** Conduct iterations with the following steps in Persian (Farsi):
37
  - **DCE's Instructions:** Provide instructions for PEE and CAE.
38
  - **PEE Output:** Generate or refine chatbot prompt, knowledge base, and FAQ.
39
  - **CAE Analysis:** Critique PEE outputs and suggest improvements.
40
  - **DCE Summary:** Summarize progress and set goals for the next iteration.
41
  4. **Iterate the Process:** Continue until high-quality outputs are achieved.
42
+ 5. **Present the Final Outputs:**
43
+ - Final prompt in English with specified sections.
44
+ - Knowledge base and FAQ in JSON-like format, separated by "---".
45
 
46
+ Conduct all dialogues in Persian, but output the final prompt in English and knowledge base/FAQ in JSON-like format. Ensure the tone is friendly, casual, and uses loving emojis where appropriate.
47
  """
48
 
49
  # تابع برای تبدیل داده‌ها به فرمت JSON-serializable
 
67
  def start_process(file1, file2):
68
  global iteration_count, iteration_history, business_info, product_info
69
  iteration_count = 1
70
+ iteration_history = "سلام عزیزم! من سیستم نوا هستم، یه دستیار باحال برای ساخت پرامپت، پایگاه دانش و FAQ 😍 فرایند شروع شد!\n"
71
 
72
  # پردازش فایل‌ها
73
  business_info, product_info = process_excel_files(file1, file2)
74
  business_info_serializable = convert_to_serializable(business_info)
75
  product_info_serializable = convert_to_serializable(product_info)
76
 
77
+ # دستورات DCE
78
+ dce_instructions = f"iteration {iteration_count}: لطفاً یه پرامپت به انگلیسی (با بخش‌های Persona, Tone, Guidelines, About Us و غیره)، پایگاه دانش به فرمت JSON (با name, description, variants, objectID) و FAQ به فرمت JSON (با دسته‌بندی و جواب‌های کوتاه و دوستانه) بسازید."
79
  iteration_history += f"**دستورات DCE:** {dce_instructions}\n"
80
 
81
+ # تولید توسط PEE
82
  pee_prompt = f"""
83
  {mother_prompt}
84
+ شما Prompt Engineering Expert (PEE) هستید. بر اساس اطلاعات زیر، پرامپت، پایگاه دانش و FAQ رو بسازید:
85
  اطلاعات کسب‌وکار: {json.dumps(business_info_serializable, ensure_ascii=False)}
86
  اطلاعات محصولات: {json.dumps(product_info_serializable, ensure_ascii=False)}
87
  {dce_instructions}
88
+ خروجی رو با --- جدا کنید.
89
  """
90
  pee_response = client.chat.completions.create(
91
  model="gpt-4o",
 
94
  pee_output = pee_response.choices[0].message.content
95
  iteration_history += f"**خروجی PEE:**\n{pee_output}\n"
96
 
97
+ # نقد توسط CAE
98
  cae_prompt = f"""
99
  {mother_prompt}
100
+ شما Critical Analysis Expert (CAE) هستید. خروجی PEE رو نقد کنید، مطمئن شید لحن دوستانه‌ست، ساختار JSON درسته و جزئیات کافی داره:
101
  خروجی PEE:\n{pee_output}
102
  """
103
  cae_response = client.chat.completions.create(
 
107
  cae_output = cae_response.choices[0].message.content
108
  iteration_history += f"**نقد CAE:**\n{cae_output}\n"
109
 
110
+ # جمع‌بندی DCE
111
  dce_summary = f"""
112
+ **جمع‌بندی DCE:** iteration {iteration_count} تموم شد 🌟
113
+ **وضعیت فعلی:** پرامپت، پایگاه دانش و FAQ اولیه ساخته شدن.
114
+ **اهداف بعدی:**
115
+ #G-{iteration_count}-1: بهبود لحن و جزئیات بر اساس نقد CAE.
116
+ #G-{iteration_count}-2: تکمیل فرمت JSON.
117
  **پایان iteration {iteration_count}**
118
  """
119
  iteration_history += dce_summary
 
128
  business_info_serializable = convert_to_serializable(business_info)
129
  product_info_serializable = convert_to_serializable(product_info)
130
 
131
+ # دستورات DCE
132
+ dce_instructions = f"iteration {iteration_count}: لطفاً خروجی قبلی رو بر اساس نقد CAE بهبود بدید، لحن رو دوستانه‌تر کنید و فرمت JSON رو دقیق‌تر کنید."
133
  iteration_history += f"**دستورات DCE:** {dce_instructions}\n"
134
 
135
+ # تولید توسط PEE
136
  pee_prompt = f"""
137
  {mother_prompt}
138
+ شما Prompt Engineering Expert (PEE) هستید. خروجی قبلی رو بر اساس نقد CAE بهبود بدید:
139
  اطلاعات کسب‌وکار: {json.dumps(business_info_serializable, ensure_ascii=False)}
140
  اطلاعات محصولات: {json.dumps(product_info_serializable, ensure_ascii=False)}
141
  تاریخچه iteration قبلی:\n{iteration_history}
142
  {dce_instructions}
143
+ خروجی رو با --- جدا کنید.
144
  """
145
  pee_response = client.chat.completions.create(
146
  model="gpt-4o",
 
149
  pee_output = pee_response.choices[0].message.content
150
  iteration_history += f"**خروجی PEE:**\n{pee_output}\n"
151
 
152
+ # نقد توسط CAE
153
  cae_prompt = f"""
154
  {mother_prompt}
155
+ شما Critical Analysis Expert (CAE) هستید. خروجی جدید PEE رو نقد کنید و مطمئن شید لحن دوستانه‌ست و فرمت JSON درسته:
156
  خروجی PEE:\n{pee_output}
157
  """
158
  cae_response = client.chat.completions.create(
 
162
  cae_output = cae_response.choices[0].message.content
163
  iteration_history += f"**نقد CAE:**\n{cae_output}\n"
164
 
165
+ # جمع‌بندی DCE
166
  dce_summary = f"""
167
+ **جمع‌بندی DCE:** iteration {iteration_count} تموم شد 😊
168
+ **وضعیت فعلی:** خروجی‌ها بهبود یافتن.
169
+ **اهداف بعدی:**
170
  #G-{iteration_count}-1: ادامه بهبود یا اتمام فرایند.
171
  **پایان iteration {iteration_count}**
172
  """
 
184
  # تولید خروجی نهایی
185
  final_prompt = f"""
186
  {mother_prompt}
187
+ فرایند iteration‌ها تموم شده. لطفاً خروجی نهایی رو تولید کنید:
188
+ - پرامپت چت‌بات به انگلیسی با بخش‌های: Persona, Tone, Guidelines, About Us, Responses to Common Questions, Contact Information, Additional Guidelines. لحن باید دوستانه، عامیانه، کوتاه (زیر 100 کلمه) و با ایموجی‌های جذاب باشه.
189
+ - پایگاه دانش به فرمت JSON-like با فیلدهای: name, description, variants (size و price), objectID.
190
+ - FAQ به فرمت JSON-like با دسته‌بندی‌ها (مثل Service Basics, Care Instructions)، موضوعات، سوالات و جواب‌های کوتاه و دوستانه.
191
  اطلاعات کسب‌وکار: {json.dumps(business_info_serializable, ensure_ascii=False)}
192
  اطلاعات محصولات: {json.dumps(product_info_serializable, ensure_ascii=False)}
193
  تاریخچه iteration‌ها:\n{iteration_history}
194
+ خروجی‌ها رو با --- جدا کنید.
195
  """
196
  final_response = client.chat.completions.create(
197
  model="gpt-4o",
 
201
 
202
  # جداسازی خروجی‌ها
203
  parts = final_output.split("---")
204
+ prompt_output = parts[0].strip() if len(parts) > 0 else "پرامپت تولید نشد 😔"
205
+ knowledge_base_output = parts[1].strip() if len(parts) > 1 else "پایگاه دانش تولید نشد 😕"
206
+ faq_output = parts[2].strip() if len(parts) > 2 else "FAQ تولید نشد 🥳"
207
 
208
+ iteration_history += "\n**فرایند تموم شد و خروجی نهایی آماده‌ست! 🎉**\n"
209
  return iteration_history, prompt_output, knowledge_base_output, faq_output
210
 
211
  # رابط کاربری Gradio
212
  with gr.Blocks() as demo:
213
+ gr.Markdown("# سیستم نوا 🌟")
214
  with gr.Row():
215
  file1 = gr.File(label="فرم اطلاعات اولیه وردست")
216
  file2 = gr.File(label="فرم اطلاعات محصولات/خدمات")