trobet commited on
Commit
daa40a8
·
1 Parent(s): 97be51f

Scrum paraphrase-MiniLM DeepSeek-R1-Distill-Llama-70B

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ 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
+ *.pdf filter=lfs diff=lfs merge=lfs -text
37
+ *.docx filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ /.streamlit
2
+ /.venv
3
+ /storage
4
+ /.idea
5
+
README.md CHANGED
@@ -1,13 +1,32 @@
1
  ---
2
- title: Scrum Expert
3
- emoji: 📉
4
- colorFrom: yellow
5
  colorTo: blue
6
  sdk: streamlit
7
  sdk_version: 1.42.0
8
  app_file: app.py
9
  pinned: false
10
- short_description: Scrum expert focusing on the fr/en Scrum Guides
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Test
3
+ emoji: 📚
4
+ colorFrom: purple
5
  colorTo: blue
6
  sdk: streamlit
7
  sdk_version: 1.42.0
8
  app_file: app.py
9
  pinned: false
10
+ short_description: First Space
11
  ---
12
 
13
+ # Introduction
14
+
15
+ This is a RAG showcase easily adaptable for any set of documents (mainly pdf, docx, txt, csv).
16
+
17
+ # How to run it locally ?
18
+
19
+ * Clone the git repository
20
+ * Replace the documents in ./data by your documents
21
+ * Customize the constants at the beginning of app.py
22
+ * Create a .streamlit directory
23
+ * Create a .streamlit/secrets.toml file :
24
+ `openai_key="your-akash-api-key"` (get your free key here : https://chatapi.akash.network/ > Get Started)
25
+ * With .venv activated : `pip install -r requirements.txt`
26
+ * Then `python -m streamlit run app.py`
27
+
28
+ ***Note*** : Every time you change the embedding model, it's necessary to delete the "storage" directory to rebuild the local vector db
29
+
30
+ # How to run it on a new HuggingFace Space ?
31
+
32
+ When it runs locally, just commit and push to a new HuggingFace Space. You need to fill your Akash api key as a Secret in the "Settings > Variables and secrets" section of your space.
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import os
3
+ import time
4
+
5
+ import streamlit as st
6
+ import torch
7
+ import sys
8
+
9
+ from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings, StorageContext, load_index_from_storage
10
+ from llama_index.core.chat_engine.types import ChatMode
11
+ from llama_index.embeddings.huggingface import HuggingFaceEmbedding
12
+ from llama_index.llms.openai_like import OpenAILike
13
+
14
+ PAGE_TITLE="Votre expert SCRUM"
15
+ CHAT_TITLE="Posez-moi une question sur le guide Scrum 2020 (anglais ou français)"
16
+ SYSTEM_PROMPT="Use the context information provided to assist the user. Mention the origins of the informations at the bottom of the response (file and page)."
17
+ EMBEDDING_MODEL="sentence-transformers/paraphrase-MiniLM-L6-v2" # Fast embedding model
18
+ #EMBEDDING_MODEL="BAAI/bge-m3" # Multilingual large model
19
+ LLM_MODEL="DeepSeek-R1-Distill-Llama-70B" # Available models on : https://chatapi.akash.network/documentation#models
20
+ NB_DOC_CHUNKS_TO_SEND=5
21
+ MAX_NB_TOKENS_IN_RESPONSE=1500
22
+ TEMPERATURE=0.2 # The closer to 1, the less deterministic and the more creative
23
+
24
+ API_BASE_URL="https://chatapi.akash.network/api/v1" # Changing this requires to adapt the custom_llm initialization
25
+
26
+ # Ajuster le chemin de torch.classes pour éviter le conflit
27
+ torch.classes.__path__ = []
28
+
29
+ st.set_page_config(page_title=PAGE_TITLE, layout="centered", initial_sidebar_state="auto", menu_items=None)
30
+ st.title(PAGE_TITLE)
31
+
32
+ custom_llm = OpenAILike(model=LLM_MODEL, api_base=API_BASE_URL, api_key=st.secrets["openai_key"], max_tokens=MAX_NB_TOKENS_IN_RESPONSE, temperature=TEMPERATURE)
33
+ Settings.embed_model = HuggingFaceEmbedding(model_name=EMBEDDING_MODEL)
34
+ Settings.llm=custom_llm
35
+
36
+ logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
37
+ logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
38
+
39
+ # Load and index data
40
+ @st.cache_resource
41
+ def load_data():
42
+ persist_dir = "./storage"
43
+ if not os.path.exists(persist_dir):
44
+ documents = SimpleDirectoryReader(input_dir="./data").load_data()
45
+ document_index = VectorStoreIndex.from_documents(documents)
46
+ document_index.storage_context.persist(persist_dir=persist_dir)
47
+ else:
48
+ storage_context = StorageContext.from_defaults(persist_dir=persist_dir)
49
+ document_index = load_index_from_storage(storage_context)
50
+ return document_index
51
+
52
+ start_time = time.time()
53
+
54
+ index = load_data()
55
+
56
+ end_time = time.time()
57
+ print(f"Time taken for loading embeddings: {end_time - start_time:.4f} seconds")
58
+ start_time = time.time()
59
+
60
+ if "messages" not in st.session_state.keys(): # Initialize the chat messages history
61
+ st.session_state.messages = [
62
+ {
63
+ "role": "assistant",
64
+ "content": CHAT_TITLE,
65
+ }
66
+ ]
67
+
68
+ if "chat_engine" not in st.session_state.keys(): # Initialize the chat engine
69
+ st.session_state.chat_engine = index.as_chat_engine(chat_mode=ChatMode.CONTEXT, system_prompt=SYSTEM_PROMPT, similarity_top_k=NB_DOC_CHUNKS_TO_SEND, verbose=True, streaming=True)
70
+
71
+ if prompt := st.chat_input("Posez votre question"): # Prompt for user input and save to chat history
72
+ st.session_state.messages.append({"role": "user", "content": prompt})
73
+
74
+ for message in st.session_state.messages: # Write message history to UI
75
+ with st.chat_message(message["role"]):
76
+ st.write(message["content"])
77
+
78
+ # If last message is not from assistant, generate a new response
79
+ if st.session_state.messages[-1]["role"] != "assistant":
80
+ with st.chat_message("assistant"):
81
+
82
+ start_time = time.time()
83
+
84
+ response_stream = st.session_state.chat_engine.stream_chat(prompt)
85
+ st.write_stream(response_stream.response_gen)
86
+ message = {"role": "assistant", "content": response_stream.response}
87
+ # Add response to message history
88
+ st.session_state.messages.append(message)
89
+
90
+ end_time = time.time()
91
+ print(f"Time taken for getting response: {end_time - start_time:.4f} seconds")
92
+ start_time = time.time()
data/2020-Scrum-Guide-English.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ed83eb2378459c9e5da5e695844a24c3770fba33687cafaf0a0683ad5070b3ec
3
+ size 254353
data/2020-Scrum-Guide-French.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0dd5b8f5af1f90ac81caac4194cf3cb73daef99eadfdf3799c669ad796cd3ba3
3
+ size 306931
requirements.txt ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohappyeyeballs==2.4.6
2
+ aiohttp==3.11.12
3
+ aiosignal==1.3.2
4
+ altair==5.5.0
5
+ annotated-types==0.7.0
6
+ anyio==4.8.0
7
+ attrs==25.1.0
8
+ beautifulsoup4==4.13.3
9
+ blinker==1.9.0
10
+ cachetools==5.5.1
11
+ certifi==2025.1.31
12
+ charset-normalizer==3.4.1
13
+ click==8.1.8
14
+ colorama==0.4.6
15
+ dataclasses-json==0.6.7
16
+ Deprecated==1.2.18
17
+ dirtyjson==1.0.8
18
+ distro==1.9.0
19
+ embeddings==0.0.8
20
+ filelock==3.17.0
21
+ filetype==1.2.0
22
+ frozenlist==1.5.0
23
+ fsspec==2025.2.0
24
+ gitdb==4.0.12
25
+ GitPython==3.1.44
26
+ greenlet==3.1.1
27
+ h11==0.14.0
28
+ httpcore==1.0.7
29
+ httpx==0.28.1
30
+ huggingface-hub==0.28.1
31
+ idna==3.10
32
+ Jinja2==3.1.5
33
+ jiter==0.8.2
34
+ joblib==1.4.2
35
+ jsonschema==4.23.0
36
+ jsonschema-specifications==2024.10.1
37
+ llama-index-core==0.12.16.post1
38
+ llama-index-embeddings-huggingface==0.5.1
39
+ llama-index-llms-openai==0.3.18
40
+ llama-index-llms-openai-like==0.3.3
41
+ llama-index-readers-file==0.4.4
42
+ markdown-it-py==3.0.0
43
+ MarkupSafe==3.0.2
44
+ marshmallow==3.26.1
45
+ mdurl==0.1.2
46
+ mpmath==1.3.0
47
+ multidict==6.1.0
48
+ mypy-extensions==1.0.0
49
+ narwhals==1.25.2
50
+ nest-asyncio==1.6.0
51
+ networkx==3.4.2
52
+ nltk==3.9.1
53
+ numpy==2.2.2
54
+ openai==1.61.1
55
+ packaging==24.2
56
+ pandas==2.2.3
57
+ pillow==11.1.0
58
+ propcache==0.2.1
59
+ protobuf==5.29.3
60
+ pyarrow==19.0.0
61
+ pydantic==2.10.6
62
+ pydantic_core==2.27.2
63
+ pydeck==0.9.1
64
+ Pygments==2.19.1
65
+ pypdf==5.3.0
66
+ python-dateutil==2.9.0.post0
67
+ pytz==2025.1
68
+ PyYAML==6.0.2
69
+ referencing==0.36.2
70
+ regex==2024.11.6
71
+ requests==2.32.3
72
+ rich==13.9.4
73
+ rpds-py==0.22.3
74
+ safetensors==0.5.2
75
+ scikit-learn==1.6.1
76
+ scipy==1.15.1
77
+ sentence-transformers==3.4.1
78
+ setuptools==75.8.0
79
+ six==1.17.0
80
+ smmap==5.0.2
81
+ sniffio==1.3.1
82
+ soupsieve==2.6
83
+ SQLAlchemy==2.0.38
84
+ streamlit==1.42.0
85
+ striprtf==0.0.26
86
+ sympy==1.13.1
87
+ tenacity==9.0.0
88
+ threadpoolctl==3.5.0
89
+ tiktoken==0.8.0
90
+ tokenizers==0.21.0
91
+ toml==0.10.2
92
+ torch==2.6.0
93
+ tornado==6.4.2
94
+ tqdm==4.67.1
95
+ transformers==4.48.3
96
+ typing-inspect==0.9.0
97
+ typing_extensions==4.12.2
98
+ tzdata==2025.1
99
+ urllib3==2.3.0
100
+ watchdog==6.0.0
101
+ wrapt==1.17.2
102
+ yarl==1.18.3