Spaces:
Running
Running
Upload app.py
Browse files
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['
|
| 28 |
-
return ["All
|
| 29 |
except:
|
| 30 |
-
return ["All
|
| 31 |
|
| 32 |
ARTICLE_LIST = load_articles_list()
|
| 33 |
|
|
@@ -101,10 +101,10 @@ def generate_response(message, history, rag_mode, article_filter, max_tokens, te
|
|
| 101 |
vs = get_vectorstore(backend)
|
| 102 |
if vs:
|
| 103 |
try:
|
| 104 |
-
filter_dict = {"
|
| 105 |
docs = vs.similarity_search(message, k=5, filter=filter_dict)
|
| 106 |
context = "\n\n".join([
|
| 107 |
-
f"[Category: {doc.metadata.get('
|
| 108 |
for doc in docs
|
| 109 |
])
|
| 110 |
except:
|
|
@@ -144,9 +144,14 @@ with gr.Blocks(title="Article Q&A model") as demo:
|
|
| 144 |
with gr.Row():
|
| 145 |
rag_mode = gr.Radio(
|
| 146 |
choices=list(BACKENDS.keys()),
|
| 147 |
-
value="
|
| 148 |
label="Mode"
|
| 149 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
with gr.Accordion("Advanced Generation Parameters", open=False):
|
| 152 |
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_title'].unique().tolist())
|
| 28 |
+
return ["All articles"] + articles
|
| 29 |
except:
|
| 30 |
+
return ["All articles"]
|
| 31 |
|
| 32 |
ARTICLE_LIST = load_articles_list()
|
| 33 |
|
|
|
|
| 101 |
vs = get_vectorstore(backend)
|
| 102 |
if vs:
|
| 103 |
try:
|
| 104 |
+
filter_dict = {"article_title": article_filter} if article_filter != "All articles" else None
|
| 105 |
docs = vs.similarity_search(message, k=5, filter=filter_dict)
|
| 106 |
context = "\n\n".join([
|
| 107 |
+
f"[Category: {doc.metadata.get('article_title', 'N/A')}] {doc.page_content[:700]}"
|
| 108 |
for doc in docs
|
| 109 |
])
|
| 110 |
except:
|
|
|
|
| 144 |
with gr.Row():
|
| 145 |
rag_mode = gr.Radio(
|
| 146 |
choices=list(BACKENDS.keys()),
|
| 147 |
+
value="FAISS - RAG (HNSW)",
|
| 148 |
label="Mode"
|
| 149 |
)
|
| 150 |
+
article_filter = gr.Dropdown(
|
| 151 |
+
choices=ARTICLE_LIST,
|
| 152 |
+
value="All articles",
|
| 153 |
+
label="Focus on article"
|
| 154 |
+
)
|
| 155 |
|
| 156 |
with gr.Accordion("Advanced Generation Parameters", open=False):
|
| 157 |
max_tokens = gr.Slider(256, 2048, value=900, step=64, label="Max Tokens")
|