|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import streamlit as st |
|
|
|
tab1, tab2, tab3 = st.tabs(["AI Adviseur voor niet-giftige glazuren", "Uitleg", "Voorbeeld vragen"]) |
|
|
|
|
|
|
|
|
|
|
|
with tab2: |
|
st.header("Uitleg") |
|
st.image("De fritte oven - een schets van het proces.jpg", width=200) |
|
|
|
with tab3: |
|
st.header("Voorbeeld vragen") |
|
st.write("De fritte oven - een schets van het proces:") |
|
st.image("De fritte oven - een schets van het proces.jpg", width=200) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.header('Hier alvast een klein aantal voorbeeldvragen die je aan deze AI adviseur voor niet-giftige glazuren zou kunnen stellen:', divider='rainbow') |
|
|
|
st.write("\n") |
|
st.write("Hoe kan ik thuis als hobby keramiek maken? Geef het antwoord uitsluitend en alleen in de Nederlands taal ") |
|
st.write("Geef een samenvatting in 10 zinnen. ") |
|
st.write("Geef een samenvatting in 25 bullet points. ") |
|
st.write("Geef een samenvatting in 25 bullet points. Geef het antwoord uitsluitend en alleen in de Nederlandse taal. ") |
|
st.write("Geef een samenvatting in 25 bullet points. Geef het antwoord uitsluitend en alleen in de Duitse taal. ") |
|
st.write("Explain glazing techniques to me as if I am 10 years old. ") |
|
st.write("Geef me uitleg over glazuurtechnieken alsof ik 5 jaar oud ben. Geef het antwoord uitsluitend en alleen in de Nederlandse taal.") |
|
|
|
st.write(" ... ") |
|
|
|
st.header('Voorbeeldvragen met voorbeeldantwoorden die je aan deze AI adviseur voor niet-giftige glazuren zou kunnen stellen:', divider='rainbow') |
|
|
|
st.write("Wie ben ik? (selecteer als taal Nederlands)\n") |
|
st.write("assistant avatar:") |
|
st.write("Gezien de tekst is het waarschijnlijk dat u heer Victor Benckhuijsen bent. U bent iemand die ervaring heeft opgedaan met het maken van glazuren voor keramiek, met name alkalische fritten. U heeft deze ervaring opgedaan op verschillende plekken, zoals de kunstacademie, de agrarische hogeschool en de geologie en bodemkunde. U benadrukt de waarden van veiligheid en het belang van het gebruik van non-giftige materialen. U verkoopt geen recepten, maar verstrekt wel veiligheidsattesten op verzoek. U benadrukt ook de voordelen van het gebruik van industriële fritten voor hobbyisten, omdat dit een veilige en eenvoudige manier is om non-giftige keramische glazuren te maken.") |
|
|
|
st.write(" ... ") |
|
|
|
st.header('Geavanceerde voorbeeldvragen met voorbeeldantwoorden die je aan deze AI adviseur voor niet-giftige glazuren zou kunnen stellen:', divider='rainbow') |
|
|
|
st.write("Formulate 10 diverse hypotheses related to the context and then find arguments that support and refute these hypotheses (selecteer als taal Engels)\n") |
|
st.write("assistant avatar:") |
|
st.write("""Formulate 10 diverse hypotheses related to the context and then find arguments that support and refute these hypotheses |
|
|
|
|
|
RESPONSE : |
|
|
|
Response time: 0.42764801399999897 seconds |
|
|
|
Hypothesis 1: The use of the Seger formula for representing the chemical structure of glazes in ceramics is a more accurate and reliable method than previous methods. |
|
|
|
Argument for: The Seger formula represents the chemical structure of glazes in a way that is consistent with the periodic table, dividing the components into three categories: melting point depressants, amphoteric metals, and fusible metals. This systematic approach allows ceramicists to better understand the relationships between different components and their effects on the final product. |
|
|
|
Argument against: While the Seger formula provides a systematic approach, it may not account for all the complexities and subtleties of ceramic glaze formulations. Other factors, such as particle size, impurities, and firing conditions, can also significantly impact the final product. |
|
|
|
|
|
Hypothesis 2: The addition of Zirkoonsilicaat to a glaze recipe can result in a wider range of pastel colors. |
|
|
|
Argument for: Zirkoonsilicaat has been identified as a component that can create pastel colors when added to a glaze recipe. This is because it can act as an opacifier, modifying the way light interacts with the glaze and leading to softer, pastel shades. |
|
|
|
Argument against: The addition of Zirkoonsilicaat may also have unintended consequences, such as altering the viscosity or melting point of the glaze, which could impact its overall appearance and performance. |
|
|
|
|
|
Hypothesis 3: The use of "gefritte" ceramic color pigments can result in more vibrant and consistent colors. |
|
|
|
Argument for: "Gefritte" ceramic color pigments are created through a process of heating and cooling, which can result in more consistent and vibrant colors than other pigment types. This is because the heating and cooling process can help to ensure that the pigment particles are evenly distributed throughout the glaze. |
|
|
|
Argument against: The use of "gefritte" pigments may not be suitable for all types of ceramic glazes, as the heating and cooling process can also alter the properties of the glaze itself. Additionally, the cost of "gefritte" pigments may be higher than other pigment types. |
|
|
|
|
|
Hypothesis 4: The practice of alchemy, as described in the context, was a precursor to modern scientific methods. |
|
|
|
Argument for: The alchemists described in the context were engaged in a systematic process of experimentation and observation, using a combination of objective and subjective methods. This approach bears some similarities to modern scientific methods, which emphasize careful observation, experimentation, and the development of hypotheses. |
|
|
|
Argument against: However, the alchemists' approach was also fundamentally different from modern scientific methods in that it was heavily influenced by spiritual and mystical beliefs. While the alchemists did engage in systematic observation and experimentation, they also placed a strong emphasis on the role of the individual alchemist's subjective experiences and intuitions. |
|
|
|
|
|
Hypothesis 5: The division of alchemy into "materiële" and "geestelijke" paths was a result of the increasing specialization and professionalization of scientific inquiry. |
|
|
|
Argument for: As scientific inquiry became more specialized and professionalized, it became increasingly difficult for individual researchers to maintain a holistic perspective that integrated both material and spiritual concerns. The division of alchemy into "materiële" and "geestelijke" paths may have been a response to this trend, allowing researchers to specialize in one area or the other. |
|
|
|
Argument against: However, it is also possible that the division of alchemy into "materiële" and "geestelijke" paths was a result of broader cultural and philosophical trends, rather than simply a response to the professionalization of scientific inquiry. |
|
|
|
|
|
Hypothesis 6: The Seger formula can be used to accurately predict the properties of a ceramic glaze based on its component parts. |
|
|
|
Argument for: The Seger formula provides a systematic approach to understanding the relationships between different components of a ceramic glaze, which could potentially be used to predict the properties of the final product. |
|
|
|
Argument against: However, the properties of ceramic glazes can be influenced by a wide range of factors, including particle size, impurities, and firing conditions. As a result, it may be difficult or impossible to accurately predict the properties of a ceramic glaze based solely on its component parts. |
|
|
|
|
|
Hypothesis 7: The use of clay as a starting material for ceramic glazes is a result of its unique physical and chemical properties. |
|
|
|
Argument for: Clay has a number of unique physical and chemical properties that make it well-suited for use in ceramic glazes. For example, clay is highly plastic, which means it can be easily shaped and molded. Additionally, clay undergoes a number of physical and chemical changes when heated, which can result in the formation of strong, durable ceramic materials. |
|
|
|
Argument against: However, clay is not the only possible starting material for ceramic glazes. Other materials, such as silica or alumina, can also be used to create ceramic glazes with a wide range of properties. |
|
|
|
|
|
Hypothesis 8: The practice of alchemy was primarily focused on the transformation of base metals into gold. |
|
|
|
Argument for: The transformation of base metals into gold was a central goal of many alchemists, who believed that this transformation was a symbol of spiritual enlightenment and transformation. |
|
|
|
Argument against: However, the practice of alchemy was not limited to the transformation of base metals into gold. Alchemists were also interested in a wide range of other topics, including medicine, pharmacology, and spirituality. |
|
|
|
|
|
Hypothesis 9: The properties of ceramic glazes can be altered through the addition of various additives. |
|
|
|
Argument for: The properties of ceramic glazes can be significantly altered through the addition of various additives, such as opacifiers, colorants, and fluxes. These additives can modify the way that light interacts with the glaze, as well as its melting point, viscosity, and other properties. |
|
|
|
Argument against: However, the addition of additives can also introduce new challenges and complexities into the glaze-making process. For example, some additives may interact with other components of the glaze in unpredictable ways, leading to unexpected results. |
|
|
|
|
|
Hypothesis 10: The practice of alchemy was primarily focused on the manipulation of physical materials. |
|
|
|
Argument for: The practice of alchemy did involve the manipulation of physical materials, such as metals, minerals, and chemicals. Alchemists engaged in a wide range of experimental techniques, including heating, cooling, dissolving, and mixing, in order to transform these materials. |
|
|
|
Argument against: However, the practice of alchemy was not limited to the manipulation of physical materials. Alchemists were also interested in spiritual and mystical concepts, such as the unity of matter and spirit, the transformation of the self, and the pursuit of enlightenment.""") |
|
|
|
|
|
|
|
st.write(" ... ") |
|
|
|
|
|
st.write("(wordt vervolgd)") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with tab1: |
|
st.header("AI Adviseur voor niet-giftige glazuren") |
|
st.image("De fritte oven - een schets van het proces.jpg", width=200) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from langchain_community.embeddings import FastEmbedEmbeddings |
|
|
|
import os |
|
import streamlit as st |
|
from langchain_groq import ChatGroq |
|
from langchain_community.document_loaders import WebBaseLoader |
|
|
|
from langchain_community.document_loaders import PyPDFLoader |
|
from langchain_community.embeddings import OllamaEmbeddings |
|
|
|
|
|
from langchain_community.embeddings import FastEmbedEmbeddings |
|
from langchain_community.document_loaders import PyPDFDirectoryLoader |
|
|
|
|
|
|
|
|
|
|
|
from langchain_community.document_loaders import DirectoryLoader |
|
from langchain_community.document_loaders import TextLoader |
|
import chardet |
|
|
|
from langchain_community.vectorstores import FAISS |
|
|
|
|
|
|
|
from langchain.text_splitter import RecursiveCharacterTextSplitter |
|
from langchain.chains.combine_documents import create_stuff_documents_chain |
|
from langchain_core.prompts import ChatPromptTemplate |
|
from langchain.chains import create_retrieval_chain |
|
import time |
|
from dotenv import load_dotenv |
|
|
|
import glob |
|
|
|
load_dotenv() |
|
|
|
groq_api_key = os.environ['GROQ_API_KEY'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.title("Adviseur voor niet-giftige glazuren:") |
|
st.subheader("Een gereedschap gebaseerd op Kunstmatige Intelligentie (AI) om advies te krijgen over niet-giftige keramische glazuren voor aardewerk temperatuur bereiken.") |
|
st.write("---------------------------------") |
|
st.subheader("Victor Benckhuijsen : (Glazuur technieken / Keramiek)") |
|
st.subheader("(ALL RIGHTS RESERVED)") |
|
st.image('Victor_Benckhuijsen_2.png', caption='Victor Benckhuijsen', width=100) |
|
|
|
|
|
st.subheader("Jan Bours : Artificial Intelligence / Data Science / Natural Language Processing") |
|
st.subheader("(ALL RIGHTS RESERVED)") |
|
st.image('Jan_Bours_2.png', caption='Jan Bours', width=100) |
|
st.write("---------------------------------") |
|
st.subheader("Chat with Docs - Using AI: 'mixtral-8x7b-32768' Groq Edition (Very Fast!) - VERSION 2 - April 3, 2024") |
|
st.write("---------------------------------") |
|
|
|
|
|
st.header("LIJST MET ALLE ACTUEEL GELADEN DOCUMENTEN: ") |
|
|
|
st.write("") |
|
pdf_files = glob.glob("*.pdf") |
|
|
|
for file in pdf_files: |
|
|
|
st.subheader(file) |
|
|
|
st.write("---------------------------------") |
|
|
|
|
|
start1 = time.process_time() |
|
|
|
if "vector" not in st.session_state: |
|
|
|
st.write("Even geduld a.u.b. ........") |
|
|
|
|
|
|
|
|
|
st.session_state.embeddings = FastEmbedEmbeddings() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with st.status("Laden van de PDF documenten / Splitting de teksten / Genereer de Vector Store ...", expanded=True) as status: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.write("Laden van de PDF documenten...") |
|
|
|
|
|
|
|
text_loader_kwargs={'autodetect_encoding': False} |
|
path = '../' |
|
|
|
|
|
|
|
|
|
loader = PyPDFDirectoryLoader(path, glob="**/*.pdf") |
|
docs = loader.load() |
|
st.session_state.docs = docs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.write("Splitting / chunking de teksten...") |
|
st.session_state.text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200) |
|
st.session_state.documents = st.session_state.text_splitter.split_documents(st.session_state.docs) |
|
|
|
st.write("Genereer de Vector Store (kan enige minuten duren)...") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.session_state.vector = FAISS.from_documents(st.session_state.documents, st.session_state.embeddings) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elapsed_time = time.process_time() - start1 |
|
st.write(f"Response time voor: Laden van de PDF documenten / Splitting de teksten / Genereer de Vector Store: {elapsed_time:.1f} seconds") |
|
|
|
st.write("---------------------------------") |
|
|
|
|
|
|
|
|
|
llm = ChatGroq( |
|
temperature=0.2, |
|
groq_api_key=groq_api_key, |
|
model_name='mixtral-8x7b-32768' |
|
) |
|
|
|
prompt = ChatPromptTemplate.from_template(""" |
|
Answer the following question based only on the provided context. |
|
Think step by step before providing a detailed answer. |
|
I will tip you $200 if the user finds the answer helpful. |
|
<context> |
|
{context} |
|
</context> |
|
Question: {input}""") |
|
|
|
document_chain = create_stuff_documents_chain(llm, prompt) |
|
|
|
retriever = st.session_state.vector.as_retriever() |
|
retrieval_chain = create_retrieval_chain(retriever, document_chain) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with st.sidebar: |
|
|
|
UserEmailAdress = st.text_input("Vul Uw email adres hier in: ", key="UserEmailAdress", type="password") |
|
|
|
"[Keramische ateliers Victor Benckhuijsen](https://victorglazuren.nl/)" |
|
"[Keramiek Victor Glazuren Victor Benckhuijsen - Instagram](https://www.instagram.com/benckhuijsenvictor/?hl=am-et)" |
|
"[Keramiek Victor Glazuren Victor Benckhuijsen - Facebook](https://www.facebook.com/harryjamaar)" |
|
"[Keramiek Victor Glazuren Victor Benckhuijsen - YouTube](https://www.youtube.com/@kleienhoop/videos)" |
|
|
|
st.title("💬 Chatbot") |
|
st.caption("🚀 A streamlit chatbot powered by mixtral-8x7b-32768 Groq LLM (VERY FAST !). temperature=0.2") |
|
|
|
if "messages" not in st.session_state: |
|
st.session_state["messages"] = [{"role": "assistant", "content": "Hoe kan ik U helpen?"}] |
|
|
|
for msg in st.session_state.messages: |
|
st.chat_message(msg["role"]).write(msg["content"]) |
|
|
|
|
|
|
|
option = st.selectbox( |
|
'In welke taal wilt U Uw vragen stellen en de AI laten antwoorden? Keuzemogelijkheden zijn : Nederlands, Engels, Duits, Frans, Spaans.', |
|
('Nederlands', 'Engels', 'Duits', 'Frans', 'Spaans')) |
|
|
|
st.write('You selected:', option) |
|
|
|
language_prompt = " Antwoordt uitsluitend en alleen in de taal: " + option + " en beslist niet in een andere taal!" |
|
|
|
|
|
if prompt := st.chat_input(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
original_prompt = prompt |
|
prompt = prompt + language_prompt |
|
|
|
|
|
|
|
start = time.process_time() |
|
response = retrieval_chain.invoke({"input": prompt}) |
|
|
|
elapsed_time = time.process_time() - start |
|
st.write(f"Response time van de LLM: {elapsed_time:.1f} seconds") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.session_state.messages.append({"role": "user", "content": prompt}) |
|
|
|
|
|
st.chat_message("user").write(original_prompt) |
|
|
|
|
|
msg = response["answer"] |
|
st.session_state.messages.append({"role": "assistant", "content": msg}) |
|
|
|
|
|
st.chat_message("assistant", avatar="Victor_Benckhuisen_20_percent.jpg").write(msg) |
|
|
|
|
|
with st.expander("Document Similarity Search"): |
|
|
|
for i, doc in enumerate(response["context"]): |
|
|
|
|
|
st.write(doc) |
|
st.write(f"Source Document # {i+1} : {doc.metadata['source'].split('/')[-1]}") |
|
|
|
st.write(doc.page_content) |
|
st.write("--------------------------------") |
|
|
|
|
|
|
|
|
|
with st.expander("Show total messages history of user + AI in this session up till this point"): |
|
|
|
st.write(st.session_state.messages) |
|
st.write("--------------------------------") |
|
|
|
|
|
|
|
st.write("---------------------------------") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|