semantic-kernel
semantic-kernel copied to clipboard
Updating Streamlit Python Sample to support newest version of SK
Motivation and Context
Follow-up to Issue: https://github.com/microsoft/semantic-kernel/issues/3213
Description
This Python script is a Streamlit application that uses the Semantic Kernel library to create a chatbot that can analyze and answer questions about CSV data.
Here's a step-by-step summary:
The script imports necessary libraries and initializes the Semantic Kernel with the AzureChatCompletion service.
It sets up a Streamlit interface with a title and instructions for the user.
The user can upload a CSV file via the sidebar. The uploaded file is read into a pandas DataFrame, and the first few rows are analyzed using the Semantic Kernel's "AnalyzeDataframe" function.
If the user clicks the "Check Dataframe" button, the application confirms whether the DataFrame has been analyzed and displays the first few rows.
The user can enter a message in the chat form and send it. When the "Send" button is clicked, the message is processed as a prompt.
The prompt is modified using the "DecipherPrompt" function, and then code is generated using the "GenerateCode" function.
The generated response is parsed to extract the code and the explanation. The code is executed, and if there are any errors, the "CodeRepair" function is invoked to try to fix the code. This process is attempted up to three times.
Contribution Checklist
- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone :smile: