Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,6 @@ import os
|
|
| 8 |
|
| 9 |
# Load API Keys from Hugging Face Secrets or environment variables
|
| 10 |
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
| 11 |
-
gemini_api_key = os.environ.get("GEMINI_API_KEY")
|
| 12 |
|
| 13 |
# Initialize expert roles
|
| 14 |
pee_expert = PromptEngineeringExpert(openai_api_key=openai_api_key)
|
|
@@ -18,16 +17,8 @@ dce_expert = DiscussionContinuityExpert()
|
|
| 18 |
MAX_ITERATIONS = 3 # Define maximum number of iterations
|
| 19 |
|
| 20 |
|
| 21 |
-
def nova_workflow(business_info_file, product_service_file, history=
|
| 22 |
-
|
| 23 |
-
iteration_number = 1
|
| 24 |
-
history = [] # Initialize history list to store iteration outputs
|
| 25 |
-
business_info_df = pd.read_excel(business_info_file.name)
|
| 26 |
-
product_service_df = pd.read_excel(product_service_file.name)
|
| 27 |
-
business_info_form_data = business_info_df.iloc[0].to_dict()
|
| 28 |
-
product_service_form_data = product_service_df.to_dict('records')
|
| 29 |
-
else: # **Loading state from previous iteration**
|
| 30 |
-
iteration_number = history[-1]["iteration_number"] + 1 # Increment iteration number
|
| 31 |
|
| 32 |
if iteration_number > MAX_ITERATIONS: # **Check for max iterations limit**
|
| 33 |
return (
|
|
@@ -39,7 +30,14 @@ def nova_workflow(business_info_file, product_service_file, history=None): # **
|
|
| 39 |
|
| 40 |
|
| 41 |
try:
|
| 42 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
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(
|
| 44 |
iteration_number=iteration_number,
|
| 45 |
expert_pee=pee_expert,
|
|
@@ -133,28 +131,4 @@ with gr.Blocks() as iface: # Use gr.Blocks for more control over layout and stat
|
|
| 133 |
continue_iteration_button = gr.Button("Continue Iteration", visible=False) # "Continue Iteration" Button - Initially hidden
|
| 134 |
finalize_button = gr.Button("Final Output", visible=False) # "Final Output" Button - Initially hidden
|
| 135 |
|
| 136 |
-
chatbot_prompt_output = gr.Code(language="markdown", label="Final Chatbot Prompt (English - Markdown)
|
| 137 |
-
knowledge_base_output = gr.Code(language="json", label="Knowledge Base (JSON-like)")
|
| 138 |
-
faq_section_output = gr.Code(language="json", label="FAQ Section (JSON-like)")
|
| 139 |
-
|
| 140 |
-
generate_button.click( # Event listener for "Generate" button
|
| 141 |
-
nova_workflow,
|
| 142 |
-
inputs=[business_info_file, product_service_file, history_state], # Pass history_state as input
|
| 143 |
-
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
|
| 144 |
-
)
|
| 145 |
-
|
| 146 |
-
continue_iteration_button.click( # Event listener for "Continue Iteration" button
|
| 147 |
-
nova_workflow,
|
| 148 |
-
inputs=[business_info_file, product_service_file, history_state], # Pass history_state as input
|
| 149 |
-
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
|
| 150 |
-
)
|
| 151 |
-
|
| 152 |
-
finalize_button.click( # Event listener for "Final Output" button
|
| 153 |
-
finalize_outputs,
|
| 154 |
-
inputs=[history_state], # Pass history_state as input
|
| 155 |
-
outputs=[chatbot_prompt_output, knowledge_base_output, faq_section_output, continue_iteration_button, finalize_button] # Buttons visibility in outputs
|
| 156 |
-
)
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
if __name__ == "__main__":
|
| 160 |
-
iface.launch()
|
|
|
|
| 8 |
|
| 9 |
# Load API Keys from Hugging Face Secrets or environment variables
|
| 10 |
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
|
|
|
| 11 |
|
| 12 |
# Initialize expert roles
|
| 13 |
pee_expert = PromptEngineeringExpert(openai_api_key=openai_api_key)
|
|
|
|
| 17 |
MAX_ITERATIONS = 3 # Define maximum number of iterations
|
| 18 |
|
| 19 |
|
| 20 |
+
def nova_workflow(business_info_file, product_service_file, history=[]): # **اصلاح: تغییر مقدار پیشفرض history به []**
|
| 21 |
+
iteration_number = len(history) + 1 # **محاسبه iteration_number بر اساس طول history**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
if iteration_number > MAX_ITERATIONS: # **Check for max iterations limit**
|
| 24 |
return (
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
try:
|
| 33 |
+
# Read data from uploaded Excel files using pandas
|
| 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 |
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|