Spaces:
Running
Running
Update app.py
Browse filesCleaned verse headings, prune low relevance verses
app.py
CHANGED
|
@@ -35,8 +35,6 @@ amazon_access_id = os.getenv('AMAZON_ACCESS_ID')
|
|
| 35 |
amazon_access_secret = os.getenv('AMAZON_ACCESS_SECRET')
|
| 36 |
azure_key = os.getenv('AZURE_KEY')
|
| 37 |
|
| 38 |
-
# SLICE_TRANS = True
|
| 39 |
-
|
| 40 |
site = os.getenv('SITE')
|
| 41 |
if site == 'local':
|
| 42 |
dp = Path('./data')
|
|
@@ -570,19 +568,28 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, clip_text, d
|
|
| 570 |
if len(results) == 0:
|
| 571 |
txt = '\nSorry, no verses were found in response to your prompt\n'
|
| 572 |
bible_list.append(txt)
|
|
|
|
|
|
|
| 573 |
for (book, chapter, verse_range, verse, dp) in results:
|
| 574 |
book = bible_books.get(book, book)
|
| 575 |
verse = verse.rstrip(" )\n")
|
| 576 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
line = f'\n<h5>{book}:{chapter}:{verse_range}</h5>\n{verse}\n'
|
| 578 |
bible_list.append(line)
|
|
|
|
|
|
|
|
|
|
| 579 |
rag_txt += line
|
| 580 |
prompt = rag_txt + '.\n ' + prompt + '\nGive higher priority to the information just provided.'
|
| 581 |
else:
|
| 582 |
(results, prompt_tokens, total_tokens) = do_search(prompt, db_name, start_date, end_date)
|
| 583 |
start_date = start_date[0:4] + '-' + start_date[4:6] + '-' + start_date[6:8]
|
| 584 |
end_date = end_date[0:4] + '-' + end_date[4:6] + '-' + end_date[6:8]
|
| 585 |
-
# if SLICE_TRANS:
|
| 586 |
clip_list = []
|
| 587 |
txt = f'\n=================\n\nFollowing are Clips and YouTube Links based on your initial query for dates between {start_date} and {end_date}:\n=================\n'
|
| 588 |
clip_list.append(azure_translate_text(txt, language))
|
|
@@ -591,10 +598,6 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, clip_text, d
|
|
| 591 |
txt = '\nSorry, no results were within the start/end dates you specified\n'
|
| 592 |
clip_list.append(azure_translate_text(txt ,language))
|
| 593 |
translation_count += update_translation_count(len(txt), language)
|
| 594 |
-
# else:
|
| 595 |
-
# clip_txt = f'\n=================\n\nFollowing are Clips and YouTube Links based on your initial query for dates between {start_date} and {end_date}:\n=================\n'
|
| 596 |
-
# if len(results) == 0:
|
| 597 |
-
# clip_txt += '\nSorry, no results were within the start/end dates you specified\n'
|
| 598 |
for (name, text, time, yt_id, udate, dp) in results:
|
| 599 |
time = correct_time(time, text)
|
| 600 |
upload_date = udate.replace('"','')
|
|
|
|
| 35 |
amazon_access_secret = os.getenv('AMAZON_ACCESS_SECRET')
|
| 36 |
azure_key = os.getenv('AZURE_KEY')
|
| 37 |
|
|
|
|
|
|
|
| 38 |
site = os.getenv('SITE')
|
| 39 |
if site == 'local':
|
| 40 |
dp = Path('./data')
|
|
|
|
| 568 |
if len(results) == 0:
|
| 569 |
txt = '\nSorry, no verses were found in response to your prompt\n'
|
| 570 |
bible_list.append(txt)
|
| 571 |
+
max_dp = 0.0
|
| 572 |
+
bad_count = 0
|
| 573 |
for (book, chapter, verse_range, verse, dp) in results:
|
| 574 |
book = bible_books.get(book, book)
|
| 575 |
verse = verse.rstrip(" )\n")
|
| 576 |
+
if max_dp == 0.0:
|
| 577 |
+
max_dp = 0.5 # 0.8 * dp
|
| 578 |
+
elif dp < max_dp:
|
| 579 |
+
bad_count += 1
|
| 580 |
+
# verse = 'LESS RELEVANT: ' + verse
|
| 581 |
+
# verse = f'Book: {book}, Chapter: {chapter}, Verses: {verse_range}: {verse}'
|
| 582 |
line = f'\n<h5>{book}:{chapter}:{verse_range}</h5>\n{verse}\n'
|
| 583 |
bible_list.append(line)
|
| 584 |
+
if bad_count > 7:
|
| 585 |
+
bible_list.append('\n<h5>Only a few relevant passages were found based on your prompt<h5>\n')
|
| 586 |
+
break
|
| 587 |
rag_txt += line
|
| 588 |
prompt = rag_txt + '.\n ' + prompt + '\nGive higher priority to the information just provided.'
|
| 589 |
else:
|
| 590 |
(results, prompt_tokens, total_tokens) = do_search(prompt, db_name, start_date, end_date)
|
| 591 |
start_date = start_date[0:4] + '-' + start_date[4:6] + '-' + start_date[6:8]
|
| 592 |
end_date = end_date[0:4] + '-' + end_date[4:6] + '-' + end_date[6:8]
|
|
|
|
| 593 |
clip_list = []
|
| 594 |
txt = f'\n=================\n\nFollowing are Clips and YouTube Links based on your initial query for dates between {start_date} and {end_date}:\n=================\n'
|
| 595 |
clip_list.append(azure_translate_text(txt, language))
|
|
|
|
| 598 |
txt = '\nSorry, no results were within the start/end dates you specified\n'
|
| 599 |
clip_list.append(azure_translate_text(txt ,language))
|
| 600 |
translation_count += update_translation_count(len(txt), language)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 601 |
for (name, text, time, yt_id, udate, dp) in results:
|
| 602 |
time = correct_time(time, text)
|
| 603 |
upload_date = udate.replace('"','')
|