robertolofaro commited on
Commit
17b7627
·
verified ·
1 Parent(s): 763aeae

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +7 -7
  2. packages.txt +0 -1
  3. requirements.txt +4 -0
app.py CHANGED
@@ -6,7 +6,7 @@ import pickle
6
  from langchain_huggingface import HuggingFaceEmbeddings
7
 
8
  # ====================== CONFIG ======================
9
- repo_id = "robertolofaro/books-model"
10
 
11
  BACKENDS = {
12
  "Fast Mode (No RAG)": None,
@@ -20,7 +20,7 @@ FAISS_PATH = "faiss_index_hnsw"
20
  QDRANT_PATH = "qdrant_db"
21
  QDRANT_COLLECTION = "articles"
22
 
23
- # ====================== LOAD METADATA FOR BOOK LIST ======================
24
  def load_articles_list():
25
  try:
26
  with open("metadata.pkl", "rb") as f:
@@ -30,7 +30,7 @@ def load_articles_list():
30
  except:
31
  return ["All categories"]
32
 
33
- ARTICLE_LIST = load_article_list()
34
 
35
  # ====================== LOAD LLM ======================
36
  model_path = hf_hub_download(
@@ -89,7 +89,7 @@ When a user asks a question, your goal is to provide a structured response based
89
 
90
 
91
  # ====================== GENERATION FUNCTION ======================
92
- def generate_response(message, history, rag_mode, book_filter, max_tokens, temperature, top_p, repeat_penalty):
93
  full_prompt = f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
94
 
95
  for msg in history[-4:]:
@@ -144,8 +144,8 @@ with gr.Blocks(title="Article Q&A model") as demo:
144
  value="Fast Mode (No RAG)",
145
  label="Mode"
146
  )
147
- book_filter = gr.Dropdown(
148
- choices=BOOK_LIST,
149
  value="All categories",
150
  label="Focus on category"
151
  )
@@ -158,7 +158,7 @@ with gr.Blocks(title="Article Q&A model") as demo:
158
 
159
  gr.ChatInterface(
160
  fn=generate_response,
161
- additional_inputs=[rag_mode, book_filter, max_tokens, temperature, top_p, repeat_penalty],
162
  examples=[
163
  ["What is the potential for Italy?"],
164
  ["What is the potential for Turin?"]
 
6
  from langchain_huggingface import HuggingFaceEmbeddings
7
 
8
  # ====================== CONFIG ======================
9
+ repo_id = "robertolofaro/articles-model"
10
 
11
  BACKENDS = {
12
  "Fast Mode (No RAG)": None,
 
20
  QDRANT_PATH = "qdrant_db"
21
  QDRANT_COLLECTION = "articles"
22
 
23
+ # ====================== LOAD METADATA FOR ARTICLE LIST ======================
24
  def load_articles_list():
25
  try:
26
  with open("metadata.pkl", "rb") as f:
 
30
  except:
31
  return ["All categories"]
32
 
33
+ ARTICLE_LIST = load_articles_list()
34
 
35
  # ====================== LOAD LLM ======================
36
  model_path = hf_hub_download(
 
89
 
90
 
91
  # ====================== GENERATION FUNCTION ======================
92
+ def generate_response(message, history, rag_mode, article_filter, max_tokens, temperature, top_p, repeat_penalty):
93
  full_prompt = f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
94
 
95
  for msg in history[-4:]:
 
144
  value="Fast Mode (No RAG)",
145
  label="Mode"
146
  )
147
+ article_filter = gr.Dropdown(
148
+ choices=ARTICLE_LIST,
149
  value="All categories",
150
  label="Focus on category"
151
  )
 
158
 
159
  gr.ChatInterface(
160
  fn=generate_response,
161
+ additional_inputs=[rag_mode, article_filter, max_tokens, temperature, top_p, repeat_penalty],
162
  examples=[
163
  ["What is the potential for Italy?"],
164
  ["What is the potential for Turin?"]
packages.txt CHANGED
@@ -3,4 +3,3 @@ cmake
3
  pkg-config
4
  libopenblas-dev
5
  libopenblas0-pthread
6
- langchain_huggingface
 
3
  pkg-config
4
  libopenblas-dev
5
  libopenblas0-pthread
 
requirements.txt CHANGED
@@ -2,3 +2,7 @@ gradio
2
  huggingface_hub
3
  llama-cpp-python @ https://huggingface.co/robertolofaro/libraries_prebuilt/resolve/main/llama_cpp_python-0.3.23-py3-none-linux_x86_64.whl
4
  langchain_huggingface
 
 
 
 
 
2
  huggingface_hub
3
  llama-cpp-python @ https://huggingface.co/robertolofaro/libraries_prebuilt/resolve/main/llama_cpp_python-0.3.23-py3-none-linux_x86_64.whl
4
  langchain_huggingface
5
+ langchain-community
6
+ chromadb
7
+ faiss-cpu
8
+ qdrant-client