mery22 commited on
Commit
76858b3
1 Parent(s): a7b92f8

Upload 5 files

Browse files
Altereo logo 2023 original - eau et territoires durables (1).png ADDED
Design 3_2 (1) (1).png ADDED
Design 3_22.png ADDED
app.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from langchain_community.vectorstores import FAISS
4
+ from langchain_community.embeddings import HuggingFaceEmbeddings
5
+
6
+ from langchain_huggingface import HuggingFaceEndpoint
7
+
8
+ from langchain.prompts import PromptTemplate
9
+ from langchain.schema.runnable import RunnablePassthrough
10
+ from langchain.chains import LLMChain
11
+
12
+ from huggingface_hub import login
13
+ login(token=st.secrets["HF_TOKEN"])
14
+
15
+ from langchain_community.document_loaders import TextLoader
16
+ from langchain_text_splitters import CharacterTextSplitter
17
+ from langchain_community.document_loaders import PyPDFLoader
18
+ from langchain.chains import RetrievalQA
19
+ from langchain.prompts import PromptTemplate
20
+ from langchain.embeddings.huggingface import HuggingFaceEmbeddings
21
+
22
+ db = FAISS.load_local("faiss_index", HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L12-v2'),allow_dangerous_deserialization=True)
23
+
24
+
25
+
26
+ retriever = db.as_retriever(
27
+ search_type="mmr",
28
+ search_kwargs={'k': 1}
29
+ )
30
+
31
+
32
+ prompt_template = """
33
+ ### [INST]
34
+ Instruction: You are a Q&A assistant. Your goal is to answer questions as accurately as possible based on the instructions and context provided without using prior knowledge.You answer in FRENCH
35
+ Analyse carefully the context and provide a direct answer based on the context. If the user said Bonjour or Hello your only answer will be Hi! comment puis-je vous aider?
36
+ Answer in french only
37
+
38
+ {context}
39
+ Vous devez répondre aux questions en français.
40
+
41
+ ### QUESTION:
42
+ {question}
43
+ [/INST]
44
+ Answer in french only
45
+ Vous devez répondre aux questions en français.
46
+
47
+ """
48
+
49
+ repo_id = "mistralai/Mistral-7B-Instruct-v0.3"
50
+
51
+ mistral_llm = HuggingFaceEndpoint(
52
+ repo_id=repo_id, max_length=2048, temperature=0.05, huggingfacehub_api_token=st.secrets["HF_TOKEN"]
53
+ )
54
+
55
+ # Create prompt from prompt template
56
+ prompt = PromptTemplate(
57
+ input_variables=["question"],
58
+ template=prompt_template,
59
+ )
60
+
61
+ # Create llm chain
62
+ llm_chain = LLMChain(llm=mistral_llm, prompt=prompt)
63
+
64
+
65
+ retriever.search_kwargs = {'k':1}
66
+ qa = RetrievalQA.from_chain_type(
67
+ llm=mistral_llm,
68
+ chain_type="stuff",
69
+ retriever=retriever,
70
+ chain_type_kwargs={"prompt": prompt},
71
+ )
72
+
73
+ import streamlit as st
74
+
75
+ # Streamlit interface with improved aesthetics
76
+ st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
77
+
78
+ # Define function to handle user input and display chatbot response
79
+ def chatbot_response(user_input):
80
+ response = qa.run(user_input)
81
+ return response
82
+
83
+
84
+ # Create columns for logos
85
+ col1, col2, col3 = st.columns([2, 3, 2])
86
+
87
+ with col1:
88
+ st.image("Design 3_22.png", width=150, use_column_width=True) # Adjust image path and size as needed
89
+
90
+ with col3:
91
+ st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True) # Adjust image path and size as needed
92
+ # Streamlit components
93
+ # Ajouter un peu de CSS pour centrer le texte
94
+ # Ajouter un peu de CSS pour centrer le texte et le colorer en orange foncé
95
+ st.markdown("""
96
+ <style>
97
+ .centered-text {
98
+ text-align: center;
99
+ }
100
+ </style>
101
+ """, unsafe_allow_html=True)
102
+
103
+ # Utiliser la classe CSS pour centrer et colorer le texte
104
+ st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
105
+ st.markdown("""
106
+ <style>
107
+ .centered-orange-text {
108
+ text-align: center;
109
+ color: darkorange;
110
+ }
111
+ </style>
112
+ """, unsafe_allow_html=True)
113
+
114
+ # Centrer le texte principal
115
+ # Centrer et colorer en orange foncé le texte spécifique
116
+ st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
117
+ # Input and button for user interaction
118
+ user_input = st.text_input("You:", "")
119
+ submit_button = st.button("Ask 📨")
120
+
121
+ # Handle user input
122
+ if submit_button:
123
+ if user_input.strip() != "":
124
+ bot_response = chatbot_response(user_input)
125
+ st.markdown("### Bot:")
126
+ st.text_area("", value=bot_response, height=600)
127
+ else:
128
+ st.warning("⚠️ Please enter a message.")
129
+
130
+ # Motivational quote at the bottom
131
+ st.markdown("---")
132
+ st.markdown("La collaboration est la clé du succès. Chaque question trouve sa réponse, chaque défi devient une opportunité.")
133
+
requirements (1).txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain_huggingface
2
+ sentence_transformers
3
+ scipy
4
+ langchain
5
+ ctransformers
6
+ tensorflow
7
+ transformers
8
+ faiss-cpu
9
+ pypdf
10
+ streamlit
11
+ langchain-community
12
+ torch
13
+ datasets
14
+ sentencepiece