tomas.helmfridsson commited on
Commit
660b98a
·
1 Parent(s): 1eab980

moved files

Browse files
Files changed (3) hide show
  1. app.py +0 -7
  2. document/app.py +0 -50
  3. document/requirements.txt +0 -8
app.py CHANGED
@@ -1,15 +1,8 @@
1
  import gradio as gr
2
- <<<<<<< HEAD
3
  from langchain_community.document_loaders import PyPDFLoader
4
  from langchain_community.vectorstores import FAISS
5
  from langchain_community.embeddings import HuggingFaceEmbeddings
6
  from langchain_community.llms import HuggingFacePipeline
7
- =======
8
- from langchain.document_loaders import PyPDFLoader
9
- from langchain.vectorstores import FAISS
10
- from langchain.embeddings import HuggingFaceEmbeddings
11
- from langchain.llms import HuggingFacePipeline
12
- >>>>>>> 2d55fcd80accaa058042bb792107864492776fea
13
  from langchain.chains import RetrievalQA
14
  from transformers import pipeline
15
  import os
 
1
  import gradio as gr
 
2
  from langchain_community.document_loaders import PyPDFLoader
3
  from langchain_community.vectorstores import FAISS
4
  from langchain_community.embeddings import HuggingFaceEmbeddings
5
  from langchain_community.llms import HuggingFacePipeline
 
 
 
 
 
 
6
  from langchain.chains import RetrievalQA
7
  from transformers import pipeline
8
  import os
document/app.py DELETED
@@ -1,50 +0,0 @@
1
- import gradio as gr
2
- from langchain_community.document_loaders import PyPDFLoader
3
- from langchain_community.vectorstores import FAISS
4
- from langchain_community.embeddings import HuggingFaceEmbeddings
5
- from langchain_community.llms import HuggingFacePipeline
6
- from langchain.chains import RetrievalQA
7
- from transformers import pipeline
8
- import os
9
-
10
- # 1. Ladda och indexera alla PDF:er i mappen "dokument/"
11
- def load_vectorstore():
12
- all_docs = []
13
- for filename in os.listdir("document"):
14
- if filename.endswith(".pdf"):
15
- path = os.path.join("document", filename)
16
- loader = PyPDFLoader(path)
17
- docs = loader.load_and_split()
18
- all_docs.extend(docs)
19
- embedding = HuggingFaceEmbeddings(model_name="KBLab/sentence-bert-swedish-cased")
20
- return FAISS.from_documents(all_docs, embedding)
21
-
22
- vectorstore = load_vectorstore()
23
-
24
- # 2. Initiera Zephyr-modellen
25
- def load_zephyr():
26
- pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta",
27
- model_kwargs={"temperature": 0.3, "max_new_tokens": 512})
28
- return HuggingFacePipeline(pipeline=pipe)
29
-
30
- llm = load_zephyr()
31
-
32
- # 3. Bygg QA-kedjan
33
- qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=vectorstore.as_retriever())
34
-
35
- # 4. Funktion för Gradio-chat
36
- chat_history = []
37
-
38
- def chat_fn(message, history):
39
- svar = qa_chain.run(message)
40
- return svar
41
-
42
- # 5. Starta Gradio-gränssnittet
43
- chatbot = gr.ChatInterface(fn=chat_fn,
44
- title="🌟 Dokumentagent på Svenska",
45
- theme="soft",
46
- examples=["Vad handlar dokumentet om?", "Finns det något om diabetes?", "Vilken åtgärd föreslås?"],
47
- retry_btn="↻ Pröva igen",
48
- submit_btn="Ställ fråga")
49
-
50
- chatbot.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
document/requirements.txt DELETED
@@ -1,8 +0,0 @@
1
- huggingface_hub==0.25.2
2
- gradio
3
- langchain
4
- transformers
5
- sentence-transformers
6
- faiss-cpu
7
- pdfminer.six
8
- langchain-community