Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .DS_Store +0 -0
- chroma_store/.DS_Store +0 -0
- main.py +25 -23
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
chroma_store/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
main.py
CHANGED
|
@@ -88,30 +88,32 @@ def llm_response(query):
|
|
| 88 |
titles, links, res_titles, res_links = [], [], [], []
|
| 89 |
try:
|
| 90 |
result = chain.invoke({"input": query})
|
|
|
|
|
|
|
| 91 |
answer = result['answer']['cited_answer'][0]["answer"]
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
answer_with_citations
|
| 115 |
|
| 116 |
# Build the references section with clickable links
|
| 117 |
citations_section = "\n\nCitations:\n" + "\n".join(
|
|
|
|
| 88 |
titles, links, res_titles, res_links = [], [], [], []
|
| 89 |
try:
|
| 90 |
result = chain.invoke({"input": query})
|
| 91 |
+
if not result['answer']['cited_answer']:
|
| 92 |
+
return "There are no articles relevant to your inquiry..."
|
| 93 |
answer = result['answer']['cited_answer'][0]["answer"]
|
| 94 |
+
if result['answer']['cited_answer']:
|
| 95 |
+
citations = result['answer']['cited_answer'][1]['citations']
|
| 96 |
+
for citation in citations:
|
| 97 |
+
edited_item = citation['citation'][1]["source"].replace("Articles/", "")
|
| 98 |
+
title, link = get_article_info(df, edited_item)
|
| 99 |
+
if title not in titles:
|
| 100 |
+
titles.append(title)
|
| 101 |
+
if link not in links:
|
| 102 |
+
links.append(link)
|
| 103 |
+
question_search = retriever.invoke(query)
|
| 104 |
+
for res_item in question_search:
|
| 105 |
+
edited_item = res_item.metadata["source"].replace("Articles/", "")
|
| 106 |
+
res_title, res_link = get_article_info(df, edited_item)
|
| 107 |
+
if res_title not in res_titles:
|
| 108 |
+
res_titles.append(res_title)
|
| 109 |
+
if res_link not in res_links:
|
| 110 |
+
res_links.append(res_link)
|
| 111 |
+
# Build the answer with superscript citations
|
| 112 |
+
answer_with_citations = f"{answer}"
|
| 113 |
+
for i, (title, link) in enumerate(zip(titles, links), start=1):
|
| 114 |
+
answer_with_citations += f" <sup>[[{i}]({link})]</sup> "
|
| 115 |
+
else:
|
| 116 |
+
answer_with_citations = f"{answer}"
|
| 117 |
|
| 118 |
# Build the references section with clickable links
|
| 119 |
citations_section = "\n\nCitations:\n" + "\n".join(
|