A newer version of the Streamlit SDK is available:
1.40.1
ToDo:
===========================================================================================================
- Get API keys and passwords from environment !: Done
===========================================================================================================
- Save the vectorstore in a persistent location !:
https://huggingface.co/docs/hub/spaces-storage !!!!! !!!!! !!!!!
Disk usage on Spaces Every Space comes with a small amount of disk storage. This disk space is ephemeral, meaning its content will be lost if your Space restarts or is stopped. If you need to persist data with a longer lifetime than the Space itself, you can:
Subscribe to a persistent storage upgrade https://huggingface.co/docs/hub/spaces-storage#persistent-storage
Use a dataset as a data store https://huggingface.co/docs/hub/spaces-storage#dataset-storage !!!!!
Persistent storage You can upgrade your Space to have access to persistent disk space from the Settings tab.
You can choose the storage tier of your choice to access disk space that persists across restarts of your Space.
Persistent storage acts like traditional disk storage mounted on /data.
That means you can read and write to this storage from your Space as you would with a traditional hard drive or SSD.
Persistent disk space can be upgraded to a larger tier at will, though it cannot be downgraded to a smaller tier. If you wish to use a smaller persistent storage tier, you must delete your current (larger) storage first.
If you are using Hugging Face open source libraries, you can make your Space restart faster by setting the environment variable HF_HOME to /data/.huggingface. Libraries like transformers, diffusers, datasets and others use that environment variable to cache any assets downloaded from the Hugging Face Hub. Setting this variable to the persistent storage path will make sure that cached resources do not need to be re-downloaded when the Space is restarted.
WARNING: all data stored in the storage is lost when you delete it. Persistent storage specs Here are the specifications for each of the different upgrade options:
Tier Disk space Persistent Monthly Price Free tier 50GB No (ephemeral) Free! Small 20GB Yes $5 Medium 150 GB Yes $25 Large 1TB Yes $100 Billing Billing of Spaces is based on hardware usage and is computed by the minute: you get charged for every minute the Space runs on the requested hardware, regardless of whether the Space is used.
Persistent storage upgrades are billed until deleted, even when the Space is not running and regardless of Space status or running state.
Additional information about billing can be found in the dedicated Hub-wide section.
Dataset storage If you need to persist data that lives longer than your Space, you could use a dataset repo.
You can find an example of persistence here, which uses the huggingface_hub library for programmatically uploading files to a dataset repository. This Space example along with this guide will help you define which solution fits best your data type.
Visit the datasets library documentation and the huggingface_hub client library documentation for more information on how to programmatically interact with dataset repos.
...
HF Spaces has an ephermal, non-persistent file storage! If you save a file from within your (streamlit) application, that file is not kept when your session has ended. Solution: save that file in a persistent location such as AWS bucket, GITHUB, or on HF.
See: julien-c/persistent-space-dataset · Datasets at Hugging Face
https://huggingface.co/datasets/julien-c/persistent-space-dataset
HF SPACES STREAMLIT APPS - GET PASSWORDS AND ACCESS TOKENS FROM HF ENVIRONMENT ! - PERSISTENT STORAGE ON HF SPACES ! - EAGLE SHELTER VERTAAL APP ETC ! - app.py · julien-c/persistent-data at main - 20-03-2024 !!!!! !!!!! !!!!!
https://huggingface.co/spaces/julien-c/persistent-data/blob/main/app.py
——->
DUPLICATED TO: https://huggingface.co/spaces/JBHF/persistent-data?logs=container
EVERNOTE : https://www.evernote.com/shard/s313/nl/41973486/1b07098e-3376-4316-abb3-b3d0996ebf03/ HF SPACES STREAMLIT APPS - GET PASSWORDS AND ACCESS TOKENS FROM HF ENVIRONMENT ! - PERSISTENT STORAGE ON HF SPACES ! - EAGLE SHELTER VERTAAL APP ETC ! - app.py · julien-c/persistent-data at main - 20-03-2024 !!!!! !!!!! !!!!!
20-03-2024
HF SPACES STREAMLIT APPS - GET PASSWORDS AND ACCESS TOKENS FROM HF ENVIRONMENT ! - PERSISTENT STORAGE ON HF SPACES ! - EAGLE SHELTER VERTAAL APP ETC ! - app.py · julien-c/persistent-data at main - 20-03-2024 !!!!! !!!!! !!!!!
https://huggingface.co/spaces/julien-c/persistent-data/blob/main/app.py
——->
DUPLICATED TO: https://huggingface.co/spaces/JBHF/persistent-data?logs=container ...
I want to persist files in a Streamlit python application on Hugging Faces. Explain me in painstakingly detail how to do that - POE WEB-SEARCH - 22-03-2024 !!!!!
POE WEB-SEARCH: https://poe.com/s/6MTNnCP4tYGFqXUgjppX
EVERNOTE : https://www.evernote.com/shard/s313/nl/41973486/87117657-5e23-497d-af42-0dac60f5e68f/ I want to persist files in a Streamlit python application on Hugging Faces. Explain me in painstakingly detail how to do that - POE WEB-SEARCH - 22-03-2024 !!!!!
22-03-2024
I want to persist files in a Streamlit python application on Hugging Faces. Explain me in painstakingly detail how to do that - POE WEB-SEARCH - 22-03-2024 !!!!!
POE WEB-SEARCH: https://poe.com/s/6MTNnCP4tYGFqXUgjppX
Knip bron: I%20want%20to%20persist%20files%20in%20a%20Streamlit%20python%20application%20on%20Hugging%20Faces.%20Explain%20me%20in%20painstakingly%20detail%20how%20to%20do%20that%20-%20Poe
Shared conversation Web-Search · 14:37
I want to persist files in a Streamlit python application on Hugging Faces. Explain me in painstakingly detail how to do that
Web-Search Poe
To persist files in a Streamlit Python application on Hugging Faces, you can follow these steps:
- Choose a storage solution: First, you need to decide on a storage solution to persist your files. Some popular options include local file storage, cloud storage services like Amazon S3 or Google Cloud Storage, or using the Hugging Face Datasets library.
- Import the necessary libraries: Depending on the storage solution you choose, you may need to import the corresponding libraries. For example, if you're using Hugging Face Datasets, you'll need to import the datasets library.
- Create a function to save the files: Write a function that takes the file data as input and saves it to the chosen storage solution. This function should handle any necessary authentication or authorization steps required by the storage solution.
- Integrate the function into your Streamlit app: In your Streamlit app, create a file upload component using the st.file_uploader function. When a file is uploaded, pass the file data to the save function you created in the previous step to persist it.
- Display the persisted files: If you want to display the persisted files in your Streamlit app, you can retrieve them from the storage solution and render them using Streamlit's built-in components like st.image or st.download_button.
Here's an example of how you can persist files using Hugging Face Datasets:
python
import streamlit as st
from datasets import Dataset
# Create a function to save the files
def save_files(file_data):
# Save the file data to a persistent dataset using Hugging Face Datasets
dataset = Dataset.from_dict({"file_data": file_data})
dataset.save_to_disk("path/to/dataset")
# Create the Streamlit app
def main():
st.title("File Upload App")
file = st.file_uploader("Upload a file")
if file is not None:
# Read the file data
file_data = file.read()
# Save the file
save_files(file_data)
st.success("File saved successfully!")
if __name__ == "__main__":
main()
In this example, the save_files function takes the file data as input and saves it to a persistent dataset using Hugging Face Datasets. The main function is the entry point of the Streamlit app and includes a file upload component. When a file is uploaded, the file data is passed to the save_files function to persist it.
Learn more:
- Save Data from Streamlit Session to Persist Changes to HF Datasets - Datasets - Hugging Face Forums
- Streamlit Spaces
- Deploy your Streamlit Web App Using Hugging Face | by Imanuelyosi | Medium
Can you provide an example of how to retrieve and display the persisted files in the Streamlit app?
Web-Search Poe
Certainly! Here's an example of how you can retrieve and display persisted files in a Streamlit app:
python
import streamlit as st
from datasets import Dataset
# Function to retrieve the persisted files
def retrieve_files():
# Load the dataset containing the persisted files using Hugging Face Datasets
dataset = Dataset.load_from_disk("path/to/dataset")
# Retrieve the file data from the dataset
file_data = dataset["file_data"]
return file_data
# Create the Streamlit app
def main():
st.title("Persisted Files App")
# Retrieve the persisted files
file_data = retrieve_files()
# Display the persisted files
if file_data:
for file in file_data:
st.write(f"File Name: {file.name}")
st.write(f"File Size: {file.size} bytes")
st.write(f"File Type: {file.type}")
st.write("---")
if __name__ == "__main__":
main()
In this example, the retrieve_files function loads the dataset containing the persisted files using Hugging Face Datasets and retrieves the file data. The main function is the entry point of the Streamlit app. It calls the retrieve_files function to get the persisted files and then displays the file name, size, and type using Streamlit's st.write function.
Learn more:
- Streamlit Share - Persist files - ☁️ Community Cloud - Streamlit
- View files from streamlit cloud - ☁️ Community Cloud - Streamlit
- Where are saved files? - Deployment - Streamlit
How can I install the Hugging Face Datasets library?
Web-Search Poe
To install the Hugging Face Datasets library, you can follow these steps:
Virtual environment: It is recommended to install Hugging Face Datasets in a virtual environment to keep things organized and avoid dependency conflicts. You can create and navigate to your project directory using the following commands:
Activate virtual environment: Start a virtual environment inside your project directory. You can activate the virtual environment with the following command:
Install with pip: The most straightforward way to install Hugging Face Datasets is using pip. Run the following command to install the library:
Verify installation: To check if Hugging Face Datasets has been properly installed, you can run the following command:
This command downloads version 1 of the Stanford Question Answering Dataset (SQuAD), loads the training split, and prints the first training example.
That's it! You have successfully installed the Hugging Face Datasets library.
Learn more:
- Installation — datasets 1.11.0 documentation - Hugging Face
- Installation
- Installation - datasets 1.16.1 documentation
How can I save a FAISS vector store file as a persistent file generated as part of a RAG application running as Streamlit application on Hugging Face Spaces
Web-Search Poe
To save a FAISS vector store file as a persistent file in a RAG application running as a Streamlit application on Hugging Face Spaces, you can follow these steps:
- Import the necessary libraries: First, make sure you have the required libraries installed. You will need faiss for working with the FAISS vector store and huggingface_hub for saving the file to a persistent location.
- Load the FAISS vector store: Use the faiss.read_index function to load the FAISS index from the vector store file. This will give you an instance of the FAISS index that you can work with.
- Perform your operations: Perform any necessary operations on the FAISS index, such as querying or updating the vectors.
- Save the FAISS index: Once you have made the desired changes to the FAISS index, you can save it as a persistent file. To do this, you can use the index.serialize method provided by FAISS. This method serializes the index into a byte array.
- Upload the serialized index: To save the serialized index as a persistent file in Hugging Face Spaces, you can use the huggingface_hub.upload_file method. This method allows you to upload a file to a specific repository on the Hugging Face Hub. You will need to provide the path to the serialized index file, the path in the repository where you want to save it, the repository ID, and your Hugging Face token.
- Access the persistent file: Once the file is uploaded, you can access it from your Streamlit application running on Hugging Face Spaces by using the appropriate URL or path.
Here is an example code snippet that demonstrates these steps:
python
import faiss
from huggingface_hub import upload_file
# Step 1: Import the necessary libraries
# Step 2: Load the FAISS vector store
index = faiss.read_index('path/to/vector_store.faiss')
# Step 3: Perform your operations
# Step 4: Save the FAISS index
serialized_index = faiss.serialize_index(index)
# Step 5: Upload the serialized index
upload_file(serialized_index, path_in_repo='path/in/repo/vector_store.faiss', repo_id='your_repo_id', token='your_token')
# Step 6: Access the persistent file
# You can access the file using the appropriate URL or path in your Streamlit application
Please note that you will need to replace 'path/to/vector_store.faiss' with the actual path to your FAISS vector store file, 'path/in/repo/vector_store.faiss' with the desired path in your repository, 'your_repo_id' with the ID of your repository on the Hugging Face Hub, and 'your_token' with your Hugging Face token.
Learn more:
- Save Data from Streamlit Session to Persist Changes to HF Datasets - Datasets - Hugging Face Forums
- Write to a file in spaces - Spaces - Hugging Face Forums
- Upload File API for Saving to Persistent Datasets on HF Spaces - Datasets - Hugging Face Forums
How can I load the FAISS index back in from the persistent file
Web-Search Poe
To load a FAISS index from a persistent file in Python, you can use the faiss.read_index function. This function allows you to read the index from a file and load it back into memory. Here's how you can do it:
python
import faiss
# Specify the path to the persistent file
filename = "path/to/index_file"
# Load the index from the persistent file
index = faiss.read_index(filename)
In the code above, you need to replace "path/to/index_file" with the actual path to your persistent file.
Once you have loaded the index, you can use it for similarity search or any other operations supported by FAISS.
Learn more:
- python - How to write a Faiss index to memory? - Stack Overflow
- Faiss: A library for efficient similarity search - Engineering at Meta
- Introduction to Facebook AI Similarity Search (Faiss) | Pinecone
This conversation may have been edited by the sharer.
Talk to Web-Search on Poe
===========================================================================================================
- Settings: wide mode as default setting
Zie: https://docs.streamlit.io/library/advanced-features/app-menu
===========================================================================================================
- File uploader:
https://docs.streamlit.io/library/api-reference/widgets/st.file_uploader
===========================================================================================================
st.title(): This function allows you to add the title of the app.
st.header(): This function is used to set header of a section.
st.markdown(): This function is used to set a markdown of a section.
st.subheader(): This function is used to set sub-header of a section.
st.caption(): This function is used to write caption.
st.code(): This function is used to set a code.
st.latex(): This function is used to display mathematical expressions formatted as LaTeX.
st.title ("this is the app title") st.header("this is the header ") st.markdown("this is the markdown") st.subheader("this is the subheader") st.caption("this is the caption") st.code("x=2021") st.latex(r''' a+a r^1+a r^2+a r^3 ''')
===========================================================================================================
Show the complete history of questions and answers:
- Gewoon chat venster met weergave van complete chat history in de actuele sessie: DONE
- ToDo: save session chat history from user + AI in a messages list (and persistently save them !)
Done (persistence not yet done !):
# Show total messages history of user + AI in this session up till this point
with st.expander("Show total messages history of user + AI in this session up till this point"):
# st.session_state.messages
st.write(st.session_state.messages)
st.write("--------------------------------")
Persisteren zou ook geïmplementeerd kunnen worden door iedere message of de complete messages history binnen een sessie te emailen !
...
===========================================================================================================
Kies de taal waarin geantwoord moet worden: - Voor Nederlands, Engels, Duits, Frans en Spaans reeds gedaan - Uitbreiden naar een veel grotere lijst met (belangrijke) wereldtalen
...
===========================================================================================================
- Choose llm temperature using a slider: Geef de temperature weer in woorden, zoals deterministisch, enigszins creatief, behoorlijk creatief, heel creatief
...
===========================================================================================================
- Possibility to choose an alternative LLM: .,
===========================================================================================================
21-03-2024: TOE TE VOEGEN:
bewaren van de vragen die users hebben gesteld (evt dmv emailen van de vragen ?)
stel bullshit vragen
Foto's van Victor en Jan tonen in app:
st.image('sunrise.jpg', caption='Sunrise by the mountains') Done
===========================================================================================================
27-03-2024: TOE TE VOEGEN / WIJZIGEN:
De chat laat nu een doorlopende conversatie zie tussen de AI en de USER, die ieder door een icoon worden gerepresenteerd. Kunnen die iconen ook door een image worden vervangen (vooral de icoon van de AI, dat zou de foto van Victor kunnen zijn, want hij geeft in principe de antwoorden (via de AI)!)
Taalkiezer: Een vraag die de goede vraagstelling heeft om puur Nederlandstalige response op te krijgen is bijvoorbeeld deze: "Ik wil zelf pottenbakken. Leg me uit wat ik daarvoor moet doen. Antwoord uitsluitend en alleen in de Nederlandse taal en beslist niet in een andere taal als Nederlands."
De toevoeging "Antwoord uitsluitend en alleen in de Nederlandse taal en beslist niet in een andere taal als Nederlands." is kennelijk voldoende om antwoorden in het Nederlands te krijgen! Dus de taalkiezer moet na een gedane keuze die toevoeging aan een USER query worden toegevoegd alvorens die query verder te verwerken.
Een geschikte talenkiezer in Streamlit is: https://docs.streamlit.io/library/api-reference/widgets/st.selectbox
Example
import streamlit as st
option = st.selectbox( 'How would you like to be contacted?', ('Email', 'Home phone', 'Mobile phone'))
st.write('You selected:', option) ...
===========================================================================================================
- STREAMLIT STATUS WEERGEVEN (VOORAL BIJ LANGDURIGE PROCESSEN, ZOALS HET GENEREREN VAN DE VECTORSTORE):
Voorbeeld code:
with st.status("Downloading data...", expanded=True) as status: st.write("Searching for data...") time.sleep(2) st.write("Found URL.") time.sleep(1) st.write("Downloading data...") time.sleep(1) status.update(label="Download complete!", state="complete", expanded=False)
===========================================================================================================
STREAMLIT MULTIPAGE APP
Om apart kiesbare pagina's te creëren voor:
- Help pagina
- Voorbeeld vragen die je aan de AI kunt stellen
- Etc
ZIE: STREAMLIT MULTIPAGE APP STARTER KIT - TBV NON-TOXIC GLAZE ADVISOR APP - 02-2024 https://dataprofessor-multipage-app-starter-kit--home-1qqhko.streamlit.app/
https://dataprofessor-multipage-app-starter-kit--home-1qqhko.streamlit.app/
dataprofessor/multipage-app-starter-kit https://github.com/dataprofessor/multipage-app-starter-kit
https://dataprofessor-multipage-app-starter-kit--home-1qqhko.streamlit.app/
https://docs.streamlit.io/library/advanced-features/multipage-apps https://docs.streamlit.io/get-started/tutorials/create-a-multipage-app https://discuss.streamlit.io/t/put-logo-and-title-above-on-top-of-page-navigation-in-sidebar-of-multipage-app/28213?u=dataprofessor
TOEPASSEN OP: https://huggingface.co/spaces/JBHF/NonToxicGlazeAdvisor_Chat_with_Docs_Groq_Edition_1?logs=container
EVERNOTE : https://www.evernote.com/shard/s313/nl/41973486/a93e39ae-d0f2-4e03-a6ec-873703f72552/ STREAMLIT MULTIPAGE APP STARTER KIT - TBV NON-TOXIC GLAZE ADVISOR APP - 02-2024 https://dataprofessor-multipage-app-starter-kit--home-1qqhko.streamlit.app/
03-04-2024
- Show a set of example questions to the user VOORBEELDVRAGEN.txt
Eerste versie vragen:
Hoe kan ik thuis als hobby keramiek maken? Geef het antwoord uitsluitend en alleen in de Nederlands taal
Geef een samenvatting in 10 zinnen.
Geef een samenvatting in 25 bullet points.
Geef een samenvatting in 25 bullet points. Geef het antwoord uitsluitend en alleen in de Nederlandse taal.
Geef een samenvatting in 25 bullet points. Geef het antwoord uitsluitend en alleen in de Duitse taal.
Explain glazing techniques to me as if I am 10 years old.
Geef me uitleg over glazuurtechnieken alsof ik 5 jaar oud ben. Geef het antwoord uitsluitend en alleen in de Nederlandse taal.
- Tab pages in streamlit? st.tabs - Streamlit Docs
https://docs.streamlit.io/library/api-reference/layout/st.tabs
Bijvoorbeeld:
import streamlit as st
tab1, tab2, tab3 = st.tabs(["Cat", "Dog", "Owl"])
with tab1: st.header("A cat") st.image("https://static.streamlit.io/examples/cat.jpg", width=200)
with tab2: st.header("A dog") st.image("https://static.streamlit.io/examples/dog.jpg", width=200)
with tab3: st.header("An owl") st.image("https://static.streamlit.io/examples/owl.jpg", width=200)
===========================================================================================================
- Word to PDF:
https://www.ilovepdf.com/word_to_pdf
===========================================================================================================
- ...