Spaces:
Sleeping
Sleeping
Update app.py
Browse files1556 unmodified lines155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159038 unmodified lines1629163016311604160516061607160816091610163216331634163593 unmodified lines17291730173117321733173417354 unmodified lines1740174117421720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174317441745174617481749174717481752175317541755175617571758175917601761174917501751175217531754175517564 unmodified lines1761176217631772176417651766176717681769177017711772177317741775177617771556 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.### 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 lines suggestion = random.choice(suggestions) return trust_tip, suggestion
def chatbot_response(message, history):
global selected_dataset_ai4 unmodified lines selected_dataset_ai = read_ai_dataset_selection()
# Recompute DATAFRAME_PROOF_POINT based on the selected dataset df_builder_pivot = compute_dataframe_proof_point()
# Filter and format the trust buckets and builders def 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 buckets formatted_buckets = format_trust_buckets(df_builder_pivot) df_builder_pivot_str = compute_dataframe_proof_point()
# Generate response using the agent executor output = agent_executor.invoke({"input": message, "chat_history": chat_history})
# Get Trust Tip and Suggestion trust_tip, suggestion = get_trust_tip_and_suggestion()
# Compile the response response = ( 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}" ) # Prepend the selected dataset to the response response = f"**Selected Dataset: {selected_dataset_ai}**\n\n{output['output']" if trust_tip not in response: # Avoid duplication response += f"\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
# Save the interaction context chat_history.extend(4 unmodified lines )
return response
except 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_ai return selected_dataset_aiapp.py+43-45