robertolofaro commited on
Commit
aa497ca
·
verified ·
1 Parent(s): 998b96e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -24,10 +24,10 @@ def load_articles_list():
24
  try:
25
  with open("metadata.pkl", "rb") as f:
26
  df = pickle.load(f)
27
- articles = sorted(df['article_title'].unique().tolist())
28
- return ["All articles"] + articles
29
  except:
30
- return ["All articles"]
31
 
32
  ARTICLE_LIST = load_articles_list()
33
 
@@ -102,10 +102,10 @@ def generate_response(message, history, rag_mode, article_filter, max_tokens, te
102
  vs = get_vectorstore(backend)
103
  if vs:
104
  try:
105
- filter_dict = {"article_title": article_filter} if article_filter != "All articles" else None
106
  docs = vs.similarity_search(message, k=5, filter=filter_dict)
107
  context = "\n\n".join([
108
- f"[Category: {doc.metadata.get('article_title', 'N/A')}] {doc.page_content[:700]}"
109
  for doc in docs
110
  ])
111
  except:
@@ -140,7 +140,7 @@ def generate_response(message, history, rag_mode, article_filter, max_tokens, te
140
  # ====================== GRADIO INTERFACE ======================
141
  with gr.Blocks(title="Article Q&A model") as demo:
142
  gr.Markdown("# sourcing 350+ articles on change")
143
- gr.Markdown("Qwen3.5-4B DoRA fine-tuned on 350+ articles - experimental (CPU-only, ie. takes few minutes) - you can enter your own question in the bottom chatbox")
144
 
145
  with gr.Row():
146
  rag_mode = gr.Radio(
@@ -148,11 +148,11 @@ with gr.Blocks(title="Article Q&A model") as demo:
148
  value="FAISS - RAG (HNSW)",
149
  label="Mode"
150
  )
151
- # article_filter = gr.Dropdown(
152
- # choices=ARTICLE_LIST,
153
- # value="All articles",
154
- # label="Focus on article"
155
- # )
156
 
157
  with gr.Accordion("Advanced Generation Parameters", open=False):
158
  max_tokens = gr.Slider(256, 2048, value=900, step=64, label="Max Tokens")
 
24
  try:
25
  with open("metadata.pkl", "rb") as f:
26
  df = pickle.load(f)
27
+ articles = sorted(df['article_category'].unique().tolist())
28
+ return ["All categories"] + articles
29
  except:
30
+ return ["All categories"]
31
 
32
  ARTICLE_LIST = load_articles_list()
33
 
 
102
  vs = get_vectorstore(backend)
103
  if vs:
104
  try:
105
+ filter_dict = {"article_category": article_filter} if article_filter != "All categories" else None
106
  docs = vs.similarity_search(message, k=5, filter=filter_dict)
107
  context = "\n\n".join([
108
+ f"[Category: {doc.metadata.get('article_category', 'N/A')}] {doc.page_content[:700]}"
109
  for doc in docs
110
  ])
111
  except:
 
140
  # ====================== GRADIO INTERFACE ======================
141
  with gr.Blocks(title="Article Q&A model") as demo:
142
  gr.Markdown("# sourcing 350+ articles on change")
143
+ gr.Markdown("Qwen3.5-4B DoRA fine-tuned on 350+ articles - experimental on CPU-only (takes few minutes, no selection for the category yet)")
144
 
145
  with gr.Row():
146
  rag_mode = gr.Radio(
 
148
  value="FAISS - RAG (HNSW)",
149
  label="Mode"
150
  )
151
+ article_filter = gr.Dropdown(
152
+ choices=ARTICLE_LIST,
153
+ value="All categories",
154
+ label="Focus on category"
155
+ )
156
 
157
  with gr.Accordion("Advanced Generation Parameters", open=False):
158
  max_tokens = gr.Slider(256, 2048, value=900, step=64, label="Max Tokens")