Spaces:
Sleeping
Sleeping
Update app.py
Browse files1556 unmodified lines15571558155915601561156238 unmodified lines160116021603160416051606160716081609161016111612161393 unmodified lines1707170817091710171117124 unmodified lines1717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317644 unmodified lines176917701771177217731774177517761777177817791556 unmodified lines- **Generate Content:**- Create the requested content type (**Annual Report**, **Social Media Post**, **Sales Conversation**, etc.).- **Integrate all Trust Proof Points into the narrative.### Content Guidelines**GENERAL INSTRUCTIONS:**- **Consistency:** Maintain a uniform format across all content types.38 unmodified lines**GENERAL QUERIES:**- For blogs or reports, refer to the knowledge base first. Focus on overall flow and structure without mentioning trust metrics unless requested.### STRICT REQUIREMENTS TO ENSURE QUALITY- **Mandatory Integration:**- **All** top three **Trust statement ** (≥18%) from each **Trust Bucket** must be **actively and explicitly integrated** into the generated content .- **Verification:**- Ensure each Trust Builder is present in the generated content.- **Formatting Enforcement:**- Display **Top scoring statements at the **top** of the output in the specified format before the main content.93 unmodified linessuggestion = random.choice(suggestions)return trust_tip, suggestiondef chatbot_response(message, history):global selected_dataset_ai4 unmodified linesselected_dataset_ai = read_ai_dataset_selection()# Recompute DATAFRAME_PROOF_POINT based on the selected datasetdf_builder_pivot = compute_dataframe_proof_point()# Filter and format the trust buckets and buildersdef format_trust_buckets(dataframe, threshold=18):"""Filters and formats Trust Buckets with top Trust Builders."""formatted_output = []for bucket in dataframe["Trust Buckets"].unique():bucket_data = dataframe[dataframe["Trust Buckets"] == bucket]top_builders = (bucket_data[bucket_data["Percentage"] >= threshold].nlargest(3, "Percentage").loc[:, ["Trust Builder", "Percentage"]])if not top_builders.empty:formatted_output.append(f"**{bucket}**\n" + "\n".join([f"- {row['Trust Builder']} [{row['Percentage']}%]" for _, row in top_builders.iterrows()]))return "\n\n".join(formatted_output)# Generate formatted trust bucketsformatted_buckets = format_trust_buckets(df_builder_pivot)# Generate response using the agent executoroutput = agent_executor.invoke({"input": message, "chat_history": chat_history})# Get Trust Tip and Suggestiontrust_tip, suggestion = get_trust_tip_and_suggestion()# Compile the responseresponse = (f"**Selected Dataset: {selected_dataset_ai}**\n\n"f"### Trust Buckets and Top Builders:\n\n{formatted_buckets}\n\n""---\n\n"f"**Chatbot Response:**\n\n{output['output']}\n\n""---\n\n"f"**Trust Tip**: {trust_tip}\n\n"f"**Suggestion**: {suggestion}")# Save the interaction contextchat_history.extend(4 unmodified lines)return responseexcept Exception as e:logger.error(f"Error generating chatbot response: {e}")return "Error occurred during response generation"def read_ai_dataset_selection():global selected_dataset_aireturn selected_dataset_ai1556 unmodified lines155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159038 unmodified lines162916301631163216331634163593 unmodified lines17291730173117321733173417354 unmodified lines174017411742174317441745174617471748174917501751175217531754175517564 unmodified lines176117621763176417651766176717681769177017711772177317741775177617771556 unmodified lines- **Generate Content:**- Create the requested content type (**Annual Report**, **Social Media Post**, **Sales Conversation**, etc.).- **Integrate all Trust Proof Points into the narrative.*STRICT REQUIREMENTS TO ENSURE QUALITY*- **Mandatory Integration:**- **All** top three **Trust statement ** (≥18%) from each *Trust Bucket** must be **actively and explicitly integrated** into the generated content .example:Like this containing 3 each.**Stability**- High-quality manufacturing [25%]- Consistent reliability [22%]- Durable materials [19%]**Development**- Future-proof technology [30%]- Innovation in design [25%]- Commitment to sustainability [20%]**Competence**- Expertise in engineering [28%]- Advanced safety features [23%]- Recognized certifications [19%]- **Verification:**- Ensure each Trust Builder is present in the generated content.- **Formatting Enforcement:**- Display **Top scoring statements at the **top** of the output in the specified format before the main content.### Content Guidelines**GENERAL INSTRUCTIONS:**- **Consistency:** Maintain a uniform format across all content types.38 unmodified lines**GENERAL QUERIES:**- For blogs or reports, refer to the knowledge base first. Focus on overall flow and structure without mentioning trust metrics unless requested.93 unmodified linessuggestion = random.choice(suggestions)return trust_tip, suggestiondef chatbot_response(message, history):global selected_dataset_ai4 unmodified linesselected_dataset_ai = read_ai_dataset_selection()# Recompute DATAFRAME_PROOF_POINT based on the selected datasetdf_builder_pivot_str = compute_dataframe_proof_point()# Generate response using the agent executoroutput = agent_executor.invoke({"input": message, "chat_history": chat_history})trust_tip, suggestion = get_trust_tip_and_suggestion()# Prepend the selected dataset to the responseresponse = f"**Selected Dataset: {selected_dataset_ai}**\n\n{output['output']"if trust_tip not in response: # Avoid duplicationresponse += f"\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"# Save the interaction contextchat_history.extend(4 unmodified lines)return responseexcept Exception as e:logger.error(f"Error generating chatbot response: {e}")return "Error occurred during response generation"def read_ai_dataset_selection():global selected_dataset_aireturn selected_dataset_ai
app.py+43-45