Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,11 +95,9 @@ def render_mermaid(mermaid_code: str):
|
|
| 95 |
|
| 96 |
def local_qa(text: str, query: str) -> str:
|
| 97 |
# A simple, local Q&A function based on keyword matching.
|
| 98 |
-
# It won't understand context, but it will find relevant sentences.
|
| 99 |
sentences = re.split(r'(?<=[.!?])\s+', text)
|
| 100 |
query_words = set(re.findall(r'\w+', query.lower()))
|
| 101 |
|
| 102 |
-
# Rank sentences by the number of query words they contain
|
| 103 |
ranked_sentences = []
|
| 104 |
for s in sentences:
|
| 105 |
s_words = set(re.findall(r'\w+', s.lower()))
|
|
@@ -109,7 +107,6 @@ def local_qa(text: str, query: str) -> str:
|
|
| 109 |
|
| 110 |
ranked_sentences.sort(key=lambda x: x[0], reverse=True)
|
| 111 |
|
| 112 |
-
# Return the top 3 most relevant sentences
|
| 113 |
if ranked_sentences:
|
| 114 |
top_sentences = [s[1] for s in ranked_sentences[:3]]
|
| 115 |
return " ".join(top_sentences)
|
|
|
|
| 95 |
|
| 96 |
def local_qa(text: str, query: str) -> str:
|
| 97 |
# A simple, local Q&A function based on keyword matching.
|
|
|
|
| 98 |
sentences = re.split(r'(?<=[.!?])\s+', text)
|
| 99 |
query_words = set(re.findall(r'\w+', query.lower()))
|
| 100 |
|
|
|
|
| 101 |
ranked_sentences = []
|
| 102 |
for s in sentences:
|
| 103 |
s_words = set(re.findall(r'\w+', s.lower()))
|
|
|
|
| 107 |
|
| 108 |
ranked_sentences.sort(key=lambda x: x[0], reverse=True)
|
| 109 |
|
|
|
|
| 110 |
if ranked_sentences:
|
| 111 |
top_sentences = [s[1] for s in ranked_sentences[:3]]
|
| 112 |
return " ".join(top_sentences)
|