add files
Browse files- .gitattributes +1 -0
- app.py +47 -0
- faiss_index/index.faiss +3 -0
- faiss_index/index.pkl +3 -0
- requirements.txt +5 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.faiss filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import textwrap
|
4 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
5 |
+
from langchain.llms import OpenAI
|
6 |
+
from langchain.prompts import PromptTemplate
|
7 |
+
from langchain.chains import RetrievalQA
|
8 |
+
from langchain.llms import OpenAI
|
9 |
+
from langchain.docstore.document import Document
|
10 |
+
from langchain.vectorstores import FAISS
|
11 |
+
|
12 |
+
# Function that sets up the generation model using the provided API key
|
13 |
+
def setup_generator(api_key):
|
14 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
15 |
+
embeddings = HuggingFaceEmbeddings(model_name="dangvantuan/sentence-camembert-base")
|
16 |
+
db = FAISS.load_local("faiss_index", embeddings)
|
17 |
+
|
18 |
+
prompt_template = """Use the following pieces of context to answer the question at the end.
|
19 |
+
Give many informations as possible.
|
20 |
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
21 |
+
|
22 |
+
{context}
|
23 |
+
|
24 |
+
Question: {question}
|
25 |
+
Answer in French:"""
|
26 |
+
PROMPT = PromptTemplate(
|
27 |
+
template=prompt_template, input_variables=["context", "question"]
|
28 |
+
)
|
29 |
+
chain_type_kwargs = {"prompt": PROMPT}
|
30 |
+
qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff",
|
31 |
+
retriever=db.as_retriever(), chain_type_kwargs=chain_type_kwargs)
|
32 |
+
return qa
|
33 |
+
|
34 |
+
def generate_text(api_key, query):
|
35 |
+
|
36 |
+
|
37 |
+
qa = setup_generator(api_key)
|
38 |
+
formatted_text = '\n'.join(textwrap.wrap(qa.run(query), width=60))
|
39 |
+
return formatted_text
|
40 |
+
|
41 |
+
iface = gr.Interface(
|
42 |
+
fn=generate_text,
|
43 |
+
inputs=[gr.inputs.Textbox(lines=1, placeholder="Input API Key..."),
|
44 |
+
gr.inputs.Textbox(lines=5, placeholder="Input Text...")],
|
45 |
+
outputs=gr.outputs.Textbox()
|
46 |
+
)
|
47 |
+
iface.launch()
|
faiss_index/index.faiss
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dc3b849e7e69be61f237fb33e681af1d1cd07b8fd2e43dcf7bb3a586e230efdc
|
3 |
+
size 156112941
|
faiss_index/index.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fb155ba8e658607b4ea588b34200131d2488bd2716967634db2c80259fb4969c
|
3 |
+
size 56496382
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
faiss-cpu
|
2 |
+
langchain[llms]
|
3 |
+
beautifulsoup4
|
4 |
+
sentence-transformers
|
5 |
+
transformers
|