Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,8 +17,16 @@ dce_expert = DiscussionContinuityExpert()
|
|
| 17 |
MAX_ITERATIONS = 3 # Define maximum number of iterations
|
| 18 |
|
| 19 |
|
| 20 |
-
def nova_workflow(business_info_file, product_service_file, history=[]): #
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
if iteration_number > MAX_ITERATIONS: # **Check for max iterations limit**
|
| 24 |
return (
|
|
@@ -30,14 +38,7 @@ def nova_workflow(business_info_file, product_service_file, history=[]): # **ا
|
|
| 30 |
|
| 31 |
|
| 32 |
try:
|
| 33 |
-
#
|
| 34 |
-
business_info_df = pd.read_excel(business_info_file.name)
|
| 35 |
-
product_service_df = pd.read_excel(product_service_file.name)
|
| 36 |
-
|
| 37 |
-
# Convert pandas DataFrames to dictionaries/JSON
|
| 38 |
-
business_info_form_data = business_info_df.iloc[0].to_dict()
|
| 39 |
-
product_service_form_data = product_service_df.to_dict('records')
|
| 40 |
-
|
| 41 |
chatbot_prompt, knowledge_base, faq_section, prompt_critique_suggestions, knowledge_base_critique_suggestions, faq_section_critique_suggestions, summary, actions, cae_analysis_summary, dce_state, goals_next_iteration, current_work_efforts, proposed_work_efforts, end_iteration_message = dce_expert.run_iteration(
|
| 42 |
iteration_number=iteration_number,
|
| 43 |
expert_pee=pee_expert,
|
|
@@ -131,4 +132,28 @@ with gr.Blocks() as iface: # Use gr.Blocks for more control over layout and stat
|
|
| 131 |
continue_iteration_button = gr.Button("Continue Iteration", visible=False) # "Continue Iteration" Button - Initially hidden
|
| 132 |
finalize_button = gr.Button("Final Output", visible=False) # "Final Output" Button - Initially hidden
|
| 133 |
|
| 134 |
-
chatbot_prompt_output = gr.Code(language="markdown", label="Final Chatbot Prompt (English - Markdown)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
MAX_ITERATIONS = 3 # Define maximum number of iterations
|
| 18 |
|
| 19 |
|
| 20 |
+
def nova_workflow(business_info_file, product_service_file, history=[]): # **Added history for state management**
|
| 21 |
+
if history is None: # **Initialization for the first iteration**
|
| 22 |
+
iteration_number = 1
|
| 23 |
+
history = [] # Initialize history list to store iteration outputs
|
| 24 |
+
business_info_df = pd.read_excel(business_info_file.name)
|
| 25 |
+
product_service_df = pd.read_excel(product_service_file.name)
|
| 26 |
+
business_info_form_data = business_info_df.iloc[0].to_dict()
|
| 27 |
+
product_service_form_data = product_service_df.to_dict('records')
|
| 28 |
+
else: # **Loading state from previous iteration**
|
| 29 |
+
iteration_number = history[-1]["iteration_number"] + 1 # Increment iteration number
|
| 30 |
|
| 31 |
if iteration_number > MAX_ITERATIONS: # **Check for max iterations limit**
|
| 32 |
return (
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
try:
|
| 41 |
+
# Run Nova System Workflow Iteration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
chatbot_prompt, knowledge_base, faq_section, prompt_critique_suggestions, knowledge_base_critique_suggestions, faq_section_critique_suggestions, summary, actions, cae_analysis_summary, dce_state, goals_next_iteration, current_work_efforts, proposed_work_efforts, end_iteration_message = dce_expert.run_iteration(
|
| 43 |
iteration_number=iteration_number,
|
| 44 |
expert_pee=pee_expert,
|
|
|
|
| 132 |
continue_iteration_button = gr.Button("Continue Iteration", visible=False) # "Continue Iteration" Button - Initially hidden
|
| 133 |
finalize_button = gr.Button("Final Output", visible=False) # "Final Output" Button - Initially hidden
|
| 134 |
|
| 135 |
+
chatbot_prompt_output = gr.Code(language="markdown", label="Final Chatbot Prompt (English - Markdown)") # **اصلاح: بستن علامت نقل قول در انتهای label**
|
| 136 |
+
knowledge_base_output = gr.Code(language="json", label="Knowledge Base (JSON-like)")
|
| 137 |
+
faq_section_output = gr.Code(language="json", label="FAQ Section (JSON-like)")
|
| 138 |
+
|
| 139 |
+
generate_button.click( # Event listener for "Generate" button
|
| 140 |
+
nova_workflow,
|
| 141 |
+
inputs=[business_info_file, product_service_file, history_state], # Pass history_state as input
|
| 142 |
+
outputs=[history_state, iteration_output_display, continue_iteration_button, finalize_button, chatbot_prompt_output, knowledge_base_output, faq_section_output] # Include history_state in outputs
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
continue_iteration_button.click( # Event listener for "Continue Iteration" button
|
| 146 |
+
nova_workflow,
|
| 147 |
+
inputs=[business_info_file, product_service_file, history_state], # Pass history_state as input
|
| 148 |
+
outputs=[history_state, iteration_output_display, continue_iteration_button, finalize_button, chatbot_prompt_output, knowledge_base_output, faq_section_output] # Include history_state in outputs
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
finalize_button.click( # Event listener for "Final Output" button
|
| 152 |
+
finalize_outputs,
|
| 153 |
+
inputs=[history_state], # Pass history_state as input
|
| 154 |
+
outputs=[chatbot_prompt_output, knowledge_base_output, faq_section_output, continue_iteration_button, finalize_button] # Buttons visibility in outputs
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
if __name__ == "__main__":
|
| 159 |
+
iface.launch()
|